[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[myserver-commit] [2780] Files refactoring.
From: |
Giuseppe Scrivano |
Subject: |
[myserver-commit] [2780] Files refactoring. |
Date: |
Tue, 02 Sep 2008 19:00:56 +0000 |
Revision: 2780
http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2780
Author: gscrivano
Date: 2008-09-02 19:00:55 +0000 (Tue, 02 Sep 2008)
Log Message:
-----------
Files refactoring. Some files were moved in a different position.
Modified Paths:
--------------
trunk/myserver/configure.in
trunk/myserver/control/myserver-configure.cpp
trunk/myserver/include/Makefile.am
trunk/myserver/include/base/Makefile.am
trunk/myserver/include/base/files_cache/cached_file.h
trunk/myserver/include/base/files_cache/cached_file_factory.h
trunk/myserver/include/http_handler/Makefile.am
trunk/myserver/include/protocol/http/Makefile.am
trunk/myserver/include/server/server.h
trunk/myserver/src/Makefile.am
trunk/myserver/src/base/Makefile.am
trunk/myserver/src/base/files_cache/cached_file.cpp
trunk/myserver/src/base/files_cache/cached_file_buffer.cpp
trunk/myserver/src/base/files_cache/cached_file_factory.cpp
trunk/myserver/src/base/find_data/find_data.cpp
trunk/myserver/src/filter/gzip/gzip_decompress.cpp
trunk/myserver/src/http_handler/Makefile.am
trunk/myserver/src/http_handler/cgi/cgi.cpp
trunk/myserver/src/http_handler/fastcgi/fastcgi.cpp
trunk/myserver/src/http_handler/isapi/isapi.cpp
trunk/myserver/src/http_handler/mscgi/mscgi.cpp
trunk/myserver/src/http_handler/scgi/scgi.cpp
trunk/myserver/src/plugin/executor/dynamic_executor.cpp
trunk/myserver/src/plugin/filter/dyn_filter.cpp
trunk/myserver/src/plugin/filter/dyn_filter_file.cpp
trunk/myserver/src/plugin/filter/dyn_filters_manager.cpp
trunk/myserver/src/plugin/generic_plugins_manager.cpp
trunk/myserver/src/plugin/http_command/dyn_http_command.cpp
trunk/myserver/src/plugin/http_manager/dyn_http_manager.cpp
trunk/myserver/src/plugin/http_manager/dyn_http_manager_list.cpp
trunk/myserver/src/plugin/plugins_namespace_manager.cpp
trunk/myserver/src/plugin/protocol/dynamic_protocol.cpp
trunk/myserver/src/plugin/protocol/protocols_manager.cpp
trunk/myserver/src/protocol/control/control_header.cpp
trunk/myserver/src/protocol/control/control_protocol.cpp
trunk/myserver/src/protocol/ftp/ftp.cpp
trunk/myserver/src/protocol/http/Makefile.am
trunk/myserver/src/protocol/http/env/env.cpp
trunk/myserver/src/protocol/http/http.cpp
trunk/myserver/src/protocol/http/http_data_read.cpp
trunk/myserver/src/protocol/http/http_headers.cpp
Added Paths:
-----------
trunk/myserver/include/base/files_cache/
trunk/myserver/include/base/files_cache/Makefile.am
trunk/myserver/include/base/find_data/
trunk/myserver/include/base/find_data/Makefile.am
trunk/myserver/include/http_handler/http_dir/
trunk/myserver/include/http_handler/http_dir/Makefile.am
trunk/myserver/include/http_handler/http_dir/http_dir.h
trunk/myserver/include/http_handler/http_file/
trunk/myserver/include/http_handler/http_file/http_file.h
trunk/myserver/include/protocol/http/env/
trunk/myserver/include/protocol/http/env/Makefile.am
trunk/myserver/src/base/files_cache/
trunk/myserver/src/base/find_data/
trunk/myserver/src/http_handler/http_dir/
trunk/myserver/src/http_handler/http_dir/http_dir.cpp
trunk/myserver/src/http_handler/http_file/
trunk/myserver/src/http_handler/http_file/http_file.cpp
trunk/myserver/src/protocol/http/env/
Removed Paths:
-------------
trunk/myserver/include/env/Makefile.am
trunk/myserver/include/env/env.h
trunk/myserver/include/files_cache/Makefile.am
trunk/myserver/include/files_cache/cached_file.h
trunk/myserver/include/files_cache/cached_file_buffer.h
trunk/myserver/include/files_cache/cached_file_factory.h
trunk/myserver/include/find_data/Makefile.am
trunk/myserver/include/find_data/find_data.h
trunk/myserver/include/protocol/http/http_dir.h
trunk/myserver/include/protocol/http/http_file.h
trunk/myserver/src/env/
trunk/myserver/src/files_cache/
trunk/myserver/src/find_data/
trunk/myserver/src/protocol/http/http_dir.cpp
trunk/myserver/src/protocol/http/http_file.cpp
Modified: trunk/myserver/configure.in
===================================================================
--- trunk/myserver/configure.in 2008-09-01 19:56:39 UTC (rev 2779)
+++ trunk/myserver/configure.in 2008-09-02 19:00:55 UTC (rev 2780)
@@ -376,108 +376,115 @@
documentation/english/images/Makefile
documentation/english/style/Makefile
documentation/english/texts/Makefile
- src/find_data/Makefile
- src/connection/Makefile
- src/env/Makefile
- src/log/Makefile
- src/conf/Makefile
- src/conf/mime/Makefile
- src/conf/security/Makefile
- src/conf/vhost/Makefile
- src/connections_scheduler/Makefile
- src/http_handler/Makefile
- src/http_handler/wincgi/Makefile
- src/http_handler/cgi/Makefile
- src/http_handler/mscgi/Makefile
- src/http_handler/fastcgi/Makefile
- src/http_handler/scgi/Makefile
- src/http_handler/isapi/Makefile
- src/base/Makefile
- src/base/file/Makefile
- src/base/pipe/Makefile
- src/base/base64/Makefile
- src/base/mem_buff/Makefile
- src/base/home_dir/Makefile
- src/base/multicast/Makefile
- src/base/sync/Makefile
- src/base/safetime/Makefile
- src/base/socket/Makefile
- src/base/hash_map/Makefile
- src/base/dynamic_lib/Makefile
- src/base/process/Makefile
- src/base/md5/Makefile
- src/base/ssl/Makefile
- src/base/xml/Makefile
- src/base/string/Makefile
- src/base/regex/Makefile
- src/base/thread/Makefile
- src/protocol/Makefile
- src/protocol/ftp/Makefile
- src/protocol/control/Makefile
- src/protocol/https/Makefile
- src/protocol/http/Makefile
- src/files_cache/Makefile
- src/filter/Makefile
- src/filter/gzip/Makefile
- src/plugin/Makefile
- src/plugin/executor/Makefile
- src/plugin/http_manager/Makefile
- src/plugin/protocol/Makefile
- src/plugin/filter/Makefile
- src/plugin/http_command/Makefile
- src/server/Makefile
+ include/Makefile
+ include/find_data/Makefile
+ include/connection/Makefile
+ include/log/Makefile
+ include/conf/Makefile
+ include/conf/mime/Makefile
+ include/conf/security/Makefile
+ include/conf/vhost/Makefile
+ include/connections_scheduler/Makefile
+ include/http_handler/Makefile
+ include/http_handler/wincgi/Makefile
+ include/http_handler/cgi/Makefile
+ include/http_handler/mscgi/Makefile
+ include/http_handler/fastcgi/Makefile
+ include/http_handler/http_file/Makefile
+ include/http_handler/scgi/Makefile
+ include/http_handler/isapi/Makefile
+ include/http_handler/http_dir/Makefile
+ include/base/Makefile
+ include/base/find_data/Makefile
+ include/base/file/Makefile
+ include/base/pipe/Makefile
+ include/base/base64/Makefile
+ include/base/mem_buff/Makefile
+ include/base/home_dir/Makefile
+ include/base/multicast/Makefile
+ include/base/sync/Makefile
+ include/base/safetime/Makefile
+ include/base/socket/Makefile
+ include/base/hash_map/Makefile
+ include/base/dynamic_lib/Makefile
+ include/base/process/Makefile
+ include/base/md5/Makefile
+ include/base/ssl/Makefile
+ include/base/xml/Makefile
+ include/base/files_cache/Makefile
+ include/base/string/Makefile
+ include/base/regex/Makefile
+ include/base/thread/Makefile
+ include/protocol/Makefile
+ include/protocol/ftp/Makefile
+ include/protocol/control/Makefile
+ include/protocol/https/Makefile
+ include/protocol/http/Makefile
+ include/protocol/http/env/Makefile
+ include/filter/Makefile
+ include/filter/gzip/Makefile
+ include/plugin/Makefile
+ include/plugin/executor/Makefile
+ include/plugin/http_manager/Makefile
+ include/plugin/protocol/Makefile
+ include/plugin/filter/Makefile
+ include/plugin/http_command/Makefile
+ include/server/Makefile
src/Makefile
- include/find_data/Makefile
- include/connection/Makefile
- include/env/Makefile
- include/log/Makefile
- include/conf/Makefile
- include/conf/mime/Makefile
- include/conf/security/Makefile
- include/conf/vhost/Makefile
- include/connections_scheduler/Makefile
- include/http_handler/Makefile
- include/http_handler/wincgi/Makefile
- include/http_handler/cgi/Makefile
- include/http_handler/mscgi/Makefile
- include/http_handler/fastcgi/Makefile
- include/http_handler/scgi/Makefile
- include/http_handler/isapi/Makefile
- include/base/Makefile
- include/base/file/Makefile
- include/base/pipe/Makefile
- include/base/base64/Makefile
- include/base/mem_buff/Makefile
- include/base/home_dir/Makefile
- include/base/multicast/Makefile
- include/base/sync/Makefile
- include/base/safetime/Makefile
- include/base/socket/Makefile
- include/base/hash_map/Makefile
- include/base/dynamic_lib/Makefile
- include/base/process/Makefile
- include/base/md5/Makefile
- include/base/ssl/Makefile
- include/base/xml/Makefile
- include/base/string/Makefile
- include/base/regex/Makefile
- include/base/thread/Makefile
- include/protocol/Makefile
- include/protocol/ftp/Makefile
- include/protocol/control/Makefile
- include/protocol/https/Makefile
- include/protocol/http/Makefile
- include/files_cache/Makefile
- include/filter/Makefile
- include/filter/gzip/Makefile
- include/plugin/Makefile
- include/plugin/executor/Makefile
- include/plugin/http_manager/Makefile
- include/plugin/protocol/Makefile
- include/plugin/filter/Makefile
- include/plugin/http_command/Makefile
- include/server/Makefile
- include/Makefile
+ src/find_data/Makefile
+ src/connection/Makefile
+ src/log/Makefile
+ src/conf/Makefile
+ src/conf/mime/Makefile
+ src/conf/security/Makefile
+ src/conf/vhost/Makefile
+ src/connections_scheduler/Makefile
+ src/http_handler/Makefile
+ src/http_handler/wincgi/Makefile
+ src/http_handler/cgi/Makefile
+ src/http_handler/mscgi/Makefile
+ src/http_handler/fastcgi/Makefile
+ src/http_handler/http_file/Makefile
+ src/http_handler/scgi/Makefile
+ src/http_handler/isapi/Makefile
+ src/http_handler/http_dir/Makefile
+ src/base/Makefile
+ src/base/find_data/Makefile
+ src/base/file/Makefile
+ src/base/pipe/Makefile
+ src/base/base64/Makefile
+ src/base/mem_buff/Makefile
+ src/base/home_dir/Makefile
+ src/base/multicast/Makefile
+ src/base/sync/Makefile
+ src/base/safetime/Makefile
+ src/base/socket/Makefile
+ src/base/hash_map/Makefile
+ src/base/dynamic_lib/Makefile
+ src/base/process/Makefile
+ src/base/md5/Makefile
+ src/base/ssl/Makefile
+ src/base/xml/Makefile
+ src/base/files_cache/Makefile
+ src/base/string/Makefile
+ src/base/regex/Makefile
+ src/base/thread/Makefile
+ src/protocol/Makefile
+ src/protocol/ftp/Makefile
+ src/protocol/control/Makefile
+ src/protocol/https/Makefile
+ src/protocol/http/Makefile
+ src/protocol/http/env/Makefile
+ src/filter/Makefile
+ src/filter/gzip/Makefile
+ src/plugin/Makefile
+ src/plugin/executor/Makefile
+ src/plugin/http_manager/Makefile
+ src/plugin/protocol/Makefile
+ src/plugin/filter/Makefile
+ src/plugin/http_command/Makefile
+ src/server/Makefile
+
tests/Makefile
])
AC_OUTPUT
Modified: trunk/myserver/control/myserver-configure.cpp
===================================================================
--- trunk/myserver/control/myserver-configure.cpp 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/control/myserver-configure.cpp 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -32,7 +32,7 @@
#include "fltkconfig.h"
#include "language.h"
-#include <include/find_data/find_data.h>
+#include <include/base/find_data/find_data.h>
extern "C"
{
Modified: trunk/myserver/include/Makefile.am
===================================================================
--- trunk/myserver/include/Makefile.am 2008-09-01 19:56:39 UTC (rev 2779)
+++ trunk/myserver/include/Makefile.am 2008-09-02 19:00:55 UTC (rev 2780)
@@ -1,2 +1,2 @@
-SUBDIRS = base conf connection connections_scheduler env files_cache filter
find_data http_handler log plugin protocol server
+SUBDIRS = base conf connection connections_scheduler filter find_data
http_handler log plugin protocol server
Modified: trunk/myserver/include/base/Makefile.am
===================================================================
--- trunk/myserver/include/base/Makefile.am 2008-09-01 19:56:39 UTC (rev
2779)
+++ trunk/myserver/include/base/Makefile.am 2008-09-02 19:00:55 UTC (rev
2780)
@@ -1,3 +1,3 @@
include_HEADERS = utility.h
-SUBDIRS = base64 dynamic_lib file hash_map home_dir md5 mem_buff multicast
pipe process regex safetime socket ssl string sync thread xml
+SUBDIRS = base64 dynamic_lib file files_cache find_data hash_map home_dir md5
mem_buff multicast pipe process regex safetime socket ssl string sync thread xml
Copied: trunk/myserver/include/base/files_cache (from rev 2774,
trunk/myserver/include/files_cache)
Property changes on: trunk/myserver/include/base/files_cache
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/myserver/include/base/files_cache/Makefile.am (from rev 2779,
trunk/myserver/include/files_cache/Makefile.am)
===================================================================
--- trunk/myserver/include/base/files_cache/Makefile.am
(rev 0)
+++ trunk/myserver/include/base/files_cache/Makefile.am 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -0,0 +1,3 @@
+include_HEADERS = cached_file_buffer.h cached_file_factory.h cached_file.h
+SUBDIRS =
+
Modified: trunk/myserver/include/base/files_cache/cached_file.h
===================================================================
--- trunk/myserver/include/files_cache/cached_file.h 2008-08-31 23:22:09 UTC
(rev 2774)
+++ trunk/myserver/include/base/files_cache/cached_file.h 2008-09-02
19:00:55 UTC (rev 2780)
@@ -21,7 +21,7 @@
#include "stdafx.h"
#include <include/filter/stream.h>
#include <include/base/file/file.h>
-#include <include/files_cache/cached_file_buffer.h>
+#include <include/base/files_cache/cached_file_buffer.h>
#include <string>
using namespace std;
Modified: trunk/myserver/include/base/files_cache/cached_file_factory.h
===================================================================
--- trunk/myserver/include/files_cache/cached_file_factory.h 2008-08-31
23:22:09 UTC (rev 2774)
+++ trunk/myserver/include/base/files_cache/cached_file_factory.h
2008-09-02 19:00:55 UTC (rev 2780)
@@ -23,8 +23,8 @@
#include <include/base/hash_map/hash_map.h>
#include <include/base/file/file.h>
#include <include/base/sync/mutex.h>
-#include <include/files_cache/cached_file.h>
-#include <include/files_cache/cached_file_buffer.h>
+#include <include/base/files_cache/cached_file.h>
+#include <include/base/files_cache/cached_file_buffer.h>
#include <string>
#include <list>
Copied: trunk/myserver/include/base/find_data (from rev 2774,
trunk/myserver/include/find_data)
Property changes on: trunk/myserver/include/base/find_data
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/myserver/include/base/find_data/Makefile.am (from rev 2779,
trunk/myserver/include/find_data/Makefile.am)
===================================================================
--- trunk/myserver/include/base/find_data/Makefile.am
(rev 0)
+++ trunk/myserver/include/base/find_data/Makefile.am 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -0,0 +1,3 @@
+include_HEADERS = find_data.h
+SUBDIRS =
+
Deleted: trunk/myserver/include/env/Makefile.am
===================================================================
--- trunk/myserver/include/env/Makefile.am 2008-09-01 19:56:39 UTC (rev
2779)
+++ trunk/myserver/include/env/Makefile.am 2008-09-02 19:00:55 UTC (rev
2780)
@@ -1,3 +0,0 @@
-include_HEADERS = env.h
-SUBDIRS =
-
Deleted: trunk/myserver/include/env/env.h
===================================================================
--- trunk/myserver/include/env/env.h 2008-09-01 19:56:39 UTC (rev 2779)
+++ trunk/myserver/include/env/env.h 2008-09-02 19:00:55 UTC (rev 2780)
@@ -1,37 +0,0 @@
-/*
-MyServer
-Copyright (C) 2002, 2003, 2004, 2008 Free Software Foundation, Inc.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef ENV_H
-#define ENV_H
-
-#include <include/protocol/http/http_response.h>
-#include <include/protocol/http/http_request.h>
-#include <include/protocol/http/http_headers.h>
-#include <include/protocol/http/http_data_handler.h>
-
-extern const char *versionOfSoftware;
-
-class Env
-{
-public:
- static void buildEnvironmentString(HttpThreadContext*, char*, int = 1);
-private:
- static void buildProcessEnvString(MemBuf& memCgi);
- static void buildHttpHeaderEnvString(MemBuf& memCgi, HttpRequestHeader &
req);
-};
-
-#endif
Deleted: trunk/myserver/include/files_cache/Makefile.am
===================================================================
--- trunk/myserver/include/files_cache/Makefile.am 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/include/files_cache/Makefile.am 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -1,3 +0,0 @@
-include_HEADERS = cached_file_buffer.h cached_file_factory.h cached_file.h
-SUBDIRS =
-
Deleted: trunk/myserver/include/files_cache/cached_file.h
===================================================================
--- trunk/myserver/include/files_cache/cached_file.h 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/include/files_cache/cached_file.h 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -1,56 +0,0 @@
-/*
-MyServer
-Copyright (C) 2006 Free Software Foundation, Inc.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef CACHED_FILE_H
-#define CACHED_FILE_H
-
-#include "stdafx.h"
-#include <include/filter/stream.h>
-#include <include/base/file/file.h>
-#include <include/files_cache/cached_file_buffer.h>
-#include <string>
-
-using namespace std;
-
-class CachedFile : public File
-{
-protected:
- u_long fseek;
- CachedFileBuffer* buffer;
-public:
- CachedFile(CachedFileBuffer* buffer);
- virtual FileHandle getHandle();
- virtual int setHandle(FileHandle);
- virtual int readFromFile(char* ,u_long ,u_long* );
- virtual int writeToFile(const char* ,u_long ,u_long* );
- virtual int createTemporaryFile(const char* );
-
- virtual int openFile(const char*, u_long );
- virtual int openFile(string const &file, u_long opt)
- {return openFile(file.c_str(), opt);}
-
- virtual u_long getFileSize();
- virtual int setFilePointer(u_long);
-
- virtual int operator =(CachedFile);
- virtual int closeFile();
-
- /*! Inherithed from Stream. */
- virtual int write(const char* buffer, u_long len, u_long *nbw);
-
-};
-#endif
Deleted: trunk/myserver/include/files_cache/cached_file_buffer.h
===================================================================
--- trunk/myserver/include/files_cache/cached_file_buffer.h 2008-09-01
19:56:39 UTC (rev 2779)
+++ trunk/myserver/include/files_cache/cached_file_buffer.h 2008-09-02
19:00:55 UTC (rev 2780)
@@ -1,52 +0,0 @@
-/*
-MyServer
-Copyright (C) 2006, 2007 Free Software Foundation, Inc.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef CACHED_FILE_BUFFER_H
-#define CACHED_FILE_BUFFER_H
-
-#include "stdafx.h"
-#include <include/filter/stream.h>
-#include <include/base/file/file.h>
-#include <include/base/sync/mutex.h>
-#include <string>
-
-using namespace std;
-
-class CachedFileFactory;
-
-class CachedFileBuffer
-{
-public:
- void addRef();
- void decRef();
- void setFactoryToNotify(CachedFileFactory *cff);
- u_long getReferenceCounter();
- u_long getFileSize(){return fileSize;}
- CachedFileBuffer(const char* filename);
- CachedFileBuffer(File* file);
- ~CachedFileBuffer();
- const char* getFilename(){return filename.c_str();}
- const char* getBuffer(){return buffer;}
-protected:
- Mutex mutex;
- char *buffer;
- u_long refCounter;
- u_long fileSize;
- CachedFileFactory *factoryToNotify;
- string filename;
-};
-#endif
Deleted: trunk/myserver/include/files_cache/cached_file_factory.h
===================================================================
--- trunk/myserver/include/files_cache/cached_file_factory.h 2008-09-01
19:56:39 UTC (rev 2779)
+++ trunk/myserver/include/files_cache/cached_file_factory.h 2008-09-02
19:00:55 UTC (rev 2780)
@@ -1,97 +0,0 @@
-/*
-MyServer
-Copyright (C) 2006, 2007 Free Software Foundation, Inc.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef CACHED_FILE_FACTORY_H
-#define CACHED_FILE_FACTORY_H
-
-#include "stdafx.h"
-#include <include/filter/stream.h>
-#include <include/base/hash_map/hash_map.h>
-#include <include/base/file/file.h>
-#include <include/base/sync/mutex.h>
-#include <include/files_cache/cached_file.h>
-#include <include/files_cache/cached_file_buffer.h>
-#include <string>
-#include <list>
-
-using namespace std;
-
-class CachedFileFactory
-{
-public:
- CachedFileFactory();
- ~CachedFileFactory();
- CachedFileFactory(u_long m);
- void initialize(u_long size);
- void clean();
- void setSize(u_long m){size = m;}
- File *open(const char* file);
- void nullReferences(CachedFileBuffer* cfb);
-
- void setMaxSize(u_long maxSize);
- void setMinSize(u_long minSize);
- u_long getMaxSize();
- u_long getMinSize();
-protected:
-
- u_long purgeRecords();
-
-
- Mutex mutex;
-
- /*! Max elements count for this cache. */
- u_long size;
-
- /*! Size currently used. */
- u_long usedSize;
-
- /*! Number of times the cache was used. */
- u_long used;
-
- /*! Cache creation time. */
- u_long created;
-
- /*! Max size for single file. */
- u_long maxSize;
-
- /*! Min size for single file. */
- u_long minSize;
-
- struct CachedFileFactoryRecord
- {
- CachedFileBuffer* buffer;
- /*! Number of times the cache record was used. */
- u_long used;
-
- /*! Cache record creation time. */
- u_long created;
-
- /*! Last mtime for this file. */
- time_t mtime;
-
- /*! Last time we checked for the mtime of the buffered file. */
- u_long lastModTimeCheck;
-
- /*! This entry is not valid and will be removed when refCount =
0. */
- bool invalidCache;
- };
-
- list<CachedFileFactoryRecord*> buffersToRemove;
- HashMap<char*, CachedFileFactoryRecord*> buffers;
-};
-
-#endif
Deleted: trunk/myserver/include/find_data/Makefile.am
===================================================================
--- trunk/myserver/include/find_data/Makefile.am 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/include/find_data/Makefile.am 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -1,3 +0,0 @@
-include_HEADERS = find_data.h
-SUBDIRS =
-
Deleted: trunk/myserver/include/find_data/find_data.h
===================================================================
--- trunk/myserver/include/find_data/find_data.h 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/include/find_data/find_data.h 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -1,86 +0,0 @@
-/*
-MyServer
-Copyright (C) 2002, 2008 Free Software Foundation, Inc.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef FIND_DATA_H
-#define FIND_DATA_H
-
-#include "stdafx.h"
-
-extern "C"
-{
-#ifdef WIN32
-#include <io.h>
-#endif
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <stdio.h>
-#ifdef NOT_WIN
-#include <dirent.h>
-#endif
-#include <limits.h>
-}
-
-#include <string>
-
-using namespace std;
-
-#ifndef EACCES
-#define EACCES 1
-#endif
-#define MAX_NAME NAME_MAX
-
-#ifndef FILE_ATTRIBUTE_DIRECTORY
-#define FILE_ATTRIBUTE_DIRECTORY 1
-#endif
-
-#ifndef intptr_t
-#define intptr_t int
-#endif
-
-class FindData
-{
- public:
- char * name;
- int attrib;
- time_t time_write;
- off_t size;
- int findfirst(const char filename[]);
- int findfirst(string &filename){return findfirst(filename.c_str());};
- int findnext();
- int findclose();
- FindData();
- ~FindData();
-#ifdef NOT_WIN
- struct stat* getStatStruct(){return &stats;}
-#endif
-
- private:
-#ifdef WIN32
- _finddata_t fd;
- intptr_t ff;
-#endif
-
-#ifdef NOT_WIN
- string DirName;
- DIR *dh;
- struct stat stats;
-#endif
-};
-
-#endif
Modified: trunk/myserver/include/http_handler/Makefile.am
===================================================================
--- trunk/myserver/include/http_handler/Makefile.am 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/include/http_handler/Makefile.am 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -1,3 +1,3 @@
include_HEADERS =
-SUBDIRS = cgi fastcgi isapi mscgi scgi wincgi
+SUBDIRS = cgi fastcgi http_dir http_file isapi mscgi scgi wincgi
Added: trunk/myserver/include/http_handler/http_dir/Makefile.am
===================================================================
--- trunk/myserver/include/http_handler/http_dir/Makefile.am
(rev 0)
+++ trunk/myserver/include/http_handler/http_dir/Makefile.am 2008-09-02
19:00:55 UTC (rev 2780)
@@ -0,0 +1,3 @@
+include_HEADERS = http_dir.h
+SUBDIRS =
+
Copied: trunk/myserver/include/http_handler/http_dir/http_dir.h (from rev 2774,
trunk/myserver/include/protocol/http/http_dir.h)
===================================================================
--- trunk/myserver/include/http_handler/http_dir/http_dir.h
(rev 0)
+++ trunk/myserver/include/http_handler/http_dir/http_dir.h 2008-09-02
19:00:55 UTC (rev 2780)
@@ -0,0 +1,57 @@
+/*
+MyServer
+Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef HTTP_DIR_H
+#define HTTP_DIR_H
+#include "stdafx.h"
+#include <include/protocol/protocol.h>
+#include <include/protocol/http/http_headers.h>
+#include <include/protocol/http/http_data_handler.h>
+#include <list>
+
+using namespace std;
+
+class HttpDir : public HttpDataHandler
+{
+public:
+ struct FileStruct
+ {
+ string name;
+ time_t time_write;
+ int attrib;
+ off_t size;
+ };
+
+ static int load(XmlParser*);
+ static int unLoad();
+ virtual int send(HttpThreadContext*, ConnectionPtr s,
+ const char *filenamePath, const char* cgi,
+ int execute = 0, int OnlyHeader = 0);
+ HttpDir();
+ virtual ~HttpDir();
+private:
+ double formatBytes(u_long bytes, u_int power);
+ void formatHtml(string & in, string& out);
+ static bool charIsLess(char i, char j);
+ static bool compareFileStructByName (HttpDir::FileStruct i,
HttpDir::FileStruct j);
+ static bool compareFileStructByTime (HttpDir::FileStruct i,
HttpDir::FileStruct j);
+ static bool compareFileStructBySize (HttpDir::FileStruct i,
HttpDir::FileStruct j);
+ void getFormattedSize(u_long bytes, string& out);
+};
+
+
+#endif
Copied: trunk/myserver/include/http_handler/http_file/http_file.h (from rev
2774, trunk/myserver/include/protocol/http/http_file.h)
===================================================================
--- trunk/myserver/include/http_handler/http_file/http_file.h
(rev 0)
+++ trunk/myserver/include/http_handler/http_file/http_file.h 2008-09-02
19:00:55 UTC (rev 2780)
@@ -0,0 +1,50 @@
+/*
+MyServer
+Copyright (C) 2005, 2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef HTTP_FILE_H
+#define HTTP_FILE_H
+#include "stdafx.h"
+
+#include <include/protocol/protocol.h>
+#include <include/protocol/http/http_headers.h>
+#include <include/protocol/http/http_data_handler.h>
+#include <include/filter/memory_stream.h>
+
+class HttpFile : public HttpDataHandler
+{
+public:
+ static int load(XmlParser*);
+ static int unLoad();
+ virtual int send(HttpThreadContext*, ConnectionPtr s,
+ const char *filenamePath, const char* cgi,
+ int execute = 0, int OnlyHeader = 0);
+ HttpFile();
+ virtual ~HttpFile();
+private:
+ static int appendDataToHTTPChannel(HttpThreadContext* td,
+ char* buffer,
+ u_long size,
+ File* appendFile,
+ FiltersChain* chain,
+ bool append,
+ bool useChunks,
+ u_long realBufferSize,
+ MemoryStream *tmpStream);
+};
+
+
+#endif
Modified: trunk/myserver/include/protocol/http/Makefile.am
===================================================================
--- trunk/myserver/include/protocol/http/Makefile.am 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/include/protocol/http/Makefile.am 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -1,3 +1,3 @@
-include_HEADERS = http_data_handler.h http_data_read.h http_dir.h
http_errors.h http_file.h http.h http_header_checker.h http_header.h
http_headers.h http_request.h http_response.h http_thread_context.h
-SUBDIRS =
+include_HEADERS = http_data_handler.h http_data_read.h http_errors.h http.h
http_header_checker.h http_header.h http_headers.h http_request.h
http_response.h http_thread_context.h
+SUBDIRS = env
Copied: trunk/myserver/include/protocol/http/env (from rev 2774,
trunk/myserver/include/env)
Property changes on: trunk/myserver/include/protocol/http/env
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/myserver/include/protocol/http/env/Makefile.am (from rev 2779,
trunk/myserver/include/env/Makefile.am)
===================================================================
--- trunk/myserver/include/protocol/http/env/Makefile.am
(rev 0)
+++ trunk/myserver/include/protocol/http/env/Makefile.am 2008-09-02
19:00:55 UTC (rev 2780)
@@ -0,0 +1,3 @@
+include_HEADERS = env.h
+SUBDIRS =
+
Deleted: trunk/myserver/include/protocol/http/http_dir.h
===================================================================
--- trunk/myserver/include/protocol/http/http_dir.h 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/include/protocol/http/http_dir.h 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -1,57 +0,0 @@
-/*
-MyServer
-Copyright (C) 2005, 2007, 2008 Free Software Foundation, Inc.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef HTTP_DIR_H
-#define HTTP_DIR_H
-#include "stdafx.h"
-#include <include/protocol/protocol.h>
-#include <include/protocol/http/http_headers.h>
-#include <include/protocol/http/http_data_handler.h>
-#include <list>
-
-using namespace std;
-
-class HttpDir : public HttpDataHandler
-{
-public:
- struct FileStruct
- {
- string name;
- time_t time_write;
- int attrib;
- off_t size;
- };
-
- static int load(XmlParser*);
- static int unLoad();
- virtual int send(HttpThreadContext*, ConnectionPtr s,
- const char *filenamePath, const char* cgi,
- int execute = 0, int OnlyHeader = 0);
- HttpDir();
- virtual ~HttpDir();
-private:
- double formatBytes(u_long bytes, u_int power);
- void formatHtml(string & in, string& out);
- static bool charIsLess(char i, char j);
- static bool compareFileStructByName (HttpDir::FileStruct i,
HttpDir::FileStruct j);
- static bool compareFileStructByTime (HttpDir::FileStruct i,
HttpDir::FileStruct j);
- static bool compareFileStructBySize (HttpDir::FileStruct i,
HttpDir::FileStruct j);
- void getFormattedSize(u_long bytes, string& out);
-};
-
-
-#endif
Deleted: trunk/myserver/include/protocol/http/http_file.h
===================================================================
--- trunk/myserver/include/protocol/http/http_file.h 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/include/protocol/http/http_file.h 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -1,50 +0,0 @@
-/*
-MyServer
-Copyright (C) 2005, 2008 Free Software Foundation, Inc.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef HTTP_FILE_H
-#define HTTP_FILE_H
-#include "stdafx.h"
-
-#include <include/protocol/protocol.h>
-#include <include/protocol/http/http_headers.h>
-#include <include/protocol/http/http_data_handler.h>
-#include <include/filter/memory_stream.h>
-
-class HttpFile : public HttpDataHandler
-{
-public:
- static int load(XmlParser*);
- static int unLoad();
- virtual int send(HttpThreadContext*, ConnectionPtr s,
- const char *filenamePath, const char* cgi,
- int execute = 0, int OnlyHeader = 0);
- HttpFile();
- virtual ~HttpFile();
-private:
- static int appendDataToHTTPChannel(HttpThreadContext* td,
- char* buffer,
- u_long size,
- File* appendFile,
- FiltersChain* chain,
- bool append,
- bool useChunks,
- u_long realBufferSize,
- MemoryStream *tmpStream);
-};
-
-
-#endif
Modified: trunk/myserver/include/server/server.h
===================================================================
--- trunk/myserver/include/server/server.h 2008-09-01 19:56:39 UTC (rev
2779)
+++ trunk/myserver/include/server/server.h 2008-09-02 19:00:55 UTC (rev
2780)
@@ -38,7 +38,7 @@
#include <include/plugin/executor/dyn_executor_manager.h>
#include <include/base/hash_map/hash_map.h>
#include <include/base/home_dir/home_dir.h>
-#include <include/files_cache/cached_file_factory.h>
+#include <include/base/files_cache/cached_file_factory.h>
#include <include/plugin/generic_plugins_manager.h>
#include <include/base/process/process_server_manager.h>
#include <include/connections_scheduler/listen_threads.h>
Modified: trunk/myserver/src/Makefile.am
===================================================================
--- trunk/myserver/src/Makefile.am 2008-09-01 19:56:39 UTC (rev 2779)
+++ trunk/myserver/src/Makefile.am 2008-09-02 19:00:55 UTC (rev 2780)
@@ -1,50 +1,14 @@
# Makefile for MyServer (./src)
-SUBDIRS = base conf connection connections_scheduler env files_cache \
- filter find_data http_handler log
plugin protocol server
+SUBDIRS = base conf connection connections_scheduler filter find_data \
+ http_handler log plugin protocol server
.
-# STATIC_AR = find_data/libfind_data.a \
-#
connection/libconnection.a env/libenv.a\
-#
log/liblog.a conf/mime/libmime.a\
-#
conf/security/libsecurity.a conf/vhost/libvhost.a\
-#
conf/libconf.a\
-#
connections_scheduler/libconnections_scheduler.a\
-#
http_handler/wincgi/libwincgi.a\
-#
http_handler/cgi/libcgi.a\
-#
http_handler/mscgi/libmscgi.a\
-#
http_handler/fastcgi/libfastcgi.a\
-#
http_handler/scgi/libscgi.a\
-#
http_handler/isapi/libisapi.a\
-#
http_handler/libhttp_handler.a base/file/libfile.a\
-#
base/pipe/libpipe.a base/base64/libbase64.a\
-#
base/mem_buff/libmem_buff.a base/libbase.a\
-#
base/home_dir/libhome_dir.a\
-#
base/multicast/libmulticast.a base/sync/libsync.a\
-#
base/safetime/libsafetime.a\
-#
base/socket/libsocket.a\
-#
base/hash_map/libhash_map.a\
-#
base/dynamic_lib/libdynamic_lib.a\
-#
base/process/libprocess.a base/md5/libmd5.a\
-#
base/ssl/libssl.a base/xml/libxml.a\
-#
base/string/libstring.a base/regex/libregex.a\
-#
base/thread/libthread.a protocol/ftp/libftp.a\
-#
protocol/control/libcontrol.a\
-#
protocol/libprotocol.a protocol/https/libhttps.a\
-#
protocol/http/libhttp.a\
-#
files_cache/libfiles_cache.a filter/gzip/libgzip.a\
-#
filter/libfilter.a plugin/executor/libexecutor.a\
-#
plugin/http_manager/libhttp_manager.a\
-#
plugin/libplugin.a plugin/protocol/libprotocol.a\
-#
plugin/filter/libfilter.a\
-#
plugin/http_command/libhttp_command.a\
-#
server/libserver.a
+#build_subdirs:
+# list='$(SUBDIRS)'; for subdir in $$list; do \
+# (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) all) \
+# done;
-build_subdirs:
- list='$(SUBDIRS)'; for subdir in $$list; do \
- (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) all) \
- done;
-
-libmyserver.a: build_subdirs
+libmyserver.a:
rm -f libmyserver.a
find -iregex .*\\.o | xargs ar cru libmyserver.a
ranlib libmyserver.a
@@ -69,5 +33,5 @@
flex --header-file=../include/protocol/ftp/ftp_lexer.h
protocol/ftp/ftp_lexer.lpp
cp ./protocol/ftp/lex.yy.c ./protocol/ftp/ftp_lexer.cpp
-all : myserver
- cp myserver ../binaries
+all : myserver${EXEEXT}
+ cp myserver${EXEEXT} ../binaries
Modified: trunk/myserver/src/base/Makefile.am
===================================================================
--- trunk/myserver/src/base/Makefile.am 2008-09-01 19:56:39 UTC (rev 2779)
+++ trunk/myserver/src/base/Makefile.am 2008-09-02 19:00:55 UTC (rev 2780)
@@ -1,5 +1,5 @@
lib_LIBRARIES = libbase.a
libbase_a_SOURCES = utility.cpp
-SUBDIRS = base64 dynamic_lib file hash_map home_dir md5 mem_buff multicast
pipe process regex safetime socket ssl string sync thread xml
+SUBDIRS = base64 dynamic_lib file files_cache find_data hash_map home_dir md5
mem_buff multicast pipe process regex safetime socket ssl string sync thread xml
INCLUDES = $(all_includes)
Copied: trunk/myserver/src/base/files_cache (from rev 2774,
trunk/myserver/src/files_cache)
Property changes on: trunk/myserver/src/base/files_cache
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/myserver/src/base/files_cache/cached_file.cpp
===================================================================
--- trunk/myserver/src/files_cache/cached_file.cpp 2008-08-31 23:22:09 UTC
(rev 2774)
+++ trunk/myserver/src/base/files_cache/cached_file.cpp 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -20,7 +20,7 @@
#include <include/base/utility.h>
#include <include/base/string/stringutils.h>
#include <include/base/file/files_utility.h>
-#include <include/files_cache/cached_file.h>
+#include <include/base/files_cache/cached_file.h>
#ifdef NOT_WIN
extern "C" {
Modified: trunk/myserver/src/base/files_cache/cached_file_buffer.cpp
===================================================================
--- trunk/myserver/src/files_cache/cached_file_buffer.cpp 2008-08-31
23:22:09 UTC (rev 2774)
+++ trunk/myserver/src/base/files_cache/cached_file_buffer.cpp 2008-09-02
19:00:55 UTC (rev 2780)
@@ -21,8 +21,8 @@
#include <include/base/string/stringutils.h>
#include <include/base/file/file.h>
#include <include/base/file/files_utility.h>
-#include <include/files_cache/cached_file_buffer.h>
-#include <include/files_cache/cached_file_factory.h>
+#include <include/base/files_cache/cached_file_buffer.h>
+#include <include/base/files_cache/cached_file_factory.h>
#ifdef NOT_WIN
extern "C" {
Modified: trunk/myserver/src/base/files_cache/cached_file_factory.cpp
===================================================================
--- trunk/myserver/src/files_cache/cached_file_factory.cpp 2008-08-31
23:22:09 UTC (rev 2774)
+++ trunk/myserver/src/base/files_cache/cached_file_factory.cpp 2008-09-02
19:00:55 UTC (rev 2780)
@@ -20,7 +20,7 @@
#include <include/base/utility.h>
#include <include/base/string/stringutils.h>
#include <include/base/file/files_utility.h>
-#include <include/files_cache/cached_file_factory.h>
+#include <include/base/files_cache/cached_file_factory.h>
#ifdef NOT_WIN
extern "C" {
Copied: trunk/myserver/src/base/find_data (from rev 2774,
trunk/myserver/src/find_data)
Property changes on: trunk/myserver/src/base/find_data
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/myserver/src/base/find_data/find_data.cpp
===================================================================
--- trunk/myserver/src/find_data/find_data.cpp 2008-08-31 23:22:09 UTC (rev
2774)
+++ trunk/myserver/src/base/find_data/find_data.cpp 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <include/find_data/find_data.h>
+#include <include/base/find_data/find_data.h>
extern "C"
{
Modified: trunk/myserver/src/filter/gzip/gzip_decompress.cpp
===================================================================
--- trunk/myserver/src/filter/gzip/gzip_decompress.cpp 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/src/filter/gzip/gzip_decompress.cpp 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -32,7 +32,6 @@
#ifdef WIN32
#include <algorithm>
#endif
-#include <include/find_data/find_data.h>
/*!
*Initialize the gzip structure value.
Modified: trunk/myserver/src/http_handler/Makefile.am
===================================================================
--- trunk/myserver/src/http_handler/Makefile.am 2008-09-01 19:56:39 UTC (rev
2779)
+++ trunk/myserver/src/http_handler/Makefile.am 2008-09-02 19:00:55 UTC (rev
2780)
@@ -1,5 +1,5 @@
lib_LIBRARIES = libhttp_handler.a
libhttp_handler_a_SOURCES =
-SUBDIRS = cgi fastcgi isapi mscgi scgi wincgi
+SUBDIRS = cgi fastcgi http_dir http_file isapi mscgi scgi wincgi
INCLUDES = $(all_includes)
Modified: trunk/myserver/src/http_handler/cgi/cgi.cpp
===================================================================
--- trunk/myserver/src/http_handler/cgi/cgi.cpp 2008-09-01 19:56:39 UTC (rev
2779)
+++ trunk/myserver/src/http_handler/cgi/cgi.cpp 2008-09-02 19:00:55 UTC (rev
2780)
@@ -29,7 +29,7 @@
#include <include/base/utility.h>
#include <include/base/mem_buff/mem_buff.h>
#include <include/filter/filters_chain.h>
-#include <include/env/env.h>
+#include <include/protocol/http/env/env.h>
#include <include/base/pipe/pipe.h>
#include <include/protocol/http/http_data_handler.h>
Modified: trunk/myserver/src/http_handler/fastcgi/fastcgi.cpp
===================================================================
--- trunk/myserver/src/http_handler/fastcgi/fastcgi.cpp 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/src/http_handler/fastcgi/fastcgi.cpp 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -21,7 +21,7 @@
*On that site you can find samples and all the supported languages.
*/
#include <include/http_handler/fastcgi/fastcgi.h>
-#include <include/env/env.h>
+#include <include/protocol/http/env/env.h>
#include <include/protocol/http/http.h>
#include <include/base/string/stringutils.h>
#include <include/server/server.h>
Copied: trunk/myserver/src/http_handler/http_dir/http_dir.cpp (from rev 2774,
trunk/myserver/src/protocol/http/http_dir.cpp)
===================================================================
--- trunk/myserver/src/http_handler/http_dir/http_dir.cpp
(rev 0)
+++ trunk/myserver/src/http_handler/http_dir/http_dir.cpp 2008-09-02
19:00:55 UTC (rev 2780)
@@ -0,0 +1,572 @@
+/*
+MyServer
+Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h"
+#include <include/server/server.h>
+#include <include/protocol/http/http.h>
+#include <include/protocol/http/http_headers.h>
+#include <include/http_handler/http_dir/http_dir.h>
+#include <include/filter/filters_chain.h>
+#include <include/base/file/files_utility.h>
+
+extern "C"
+{
+#ifdef WIN32
+#include <direct.h>
+#include <errno.h>
+#endif
+
+#ifdef NOT_WIN
+#include <string.h>
+#include <errno.h>
+#endif
+}
+
+#include <include/base/find_data/find_data.h>
+#include <include/base/string/stringutils.h>
+#ifdef NOT_WIN
+#endif
+
+#include <string>
+#include <sstream>
+#include <vector>
+#include <algorithm>
+#include <iomanip>
+
+using namespace std;
+
+/*!
+ * Compare two HttpDir::FileStruct by their filename.
+ */
+bool HttpDir::compareFileStructByName (HttpDir::FileStruct i,
HttpDir::FileStruct j)
+{
+ return stringcmpi (i.name, j.name) < 0 ? true : false;
+}
+
+/*!
+ * Compare two HttpDir::FileStruct by their last modified file time.
+ */
+
+bool HttpDir::compareFileStructByTime (HttpDir::FileStruct i,
HttpDir::FileStruct j)
+{
+ return i.time_write < j.time_write;
+}
+
+/*!
+ * Compare two HttpDir::FileStruct by their file size.
+ */
+bool HttpDir::compareFileStructBySize (HttpDir::FileStruct i,
HttpDir::FileStruct j)
+{
+ return i.size < j.size;
+}
+
+/*!
+ *Constructor for the class.
+ */
+HttpDir::HttpDir()
+{
+
+}
+
+/*!
+ *Destroy the object.
+ */
+HttpDir::~HttpDir()
+{
+
+}
+
+/*!
+ *Load the static elements.
+ */
+int HttpDir::load(XmlParser* /*confFile*/)
+{
+ return 0;
+}
+
+/*!
+ *Unload the static elements.
+ */
+int HttpDir::unLoad()
+{
+ return 0;
+}
+
+/*!
+ *Get a formatted dobule representation of BYTES right shifted by POWER.
+ *\param bytes Number of bytes.
+ *\param power Power of 2.
+ *\return the double representation for BYTES>>POWER.
+ */
+double HttpDir::formatBytes(u_long bytes, u_int power)
+{
+ const u_long quotient = bytes >> power;
+ if (quotient == 0)
+ return -1;
+
+ const u_long unit = 1 << power;
+ const u_long remainder = bytes & (unit - 1);
+ const double result = quotient + static_cast<double>(remainder) / unit;
+ return result;
+}
+
+
+/*!
+ *Fullfill the string out with a formatted representation for bytes.
+ *\param bytes Size to format.
+ *\param out Out string.
+ */
+void HttpDir::getFormattedSize(u_long bytes, string & out)
+{
+ const string symbols[] = {"TB", "GB", "MB", "KB", "bytes"};
+ const u_int powers[] = {40, 30, 20, 10, 0};
+ double result;
+ size_t i;
+ ostringstream osstr;
+
+ if (bytes == 0)
+ {
+ out = "0";
+ return;
+ }
+
+ for (i = 0; i < sizeof (powers); i++)
+ {
+ result = formatBytes (bytes, powers[i]);
+ if (result != -1)
+ break;
+ }
+
+ if((result - floor(result)) < 0.01)
+ osstr << std::fixed << setprecision(0) << result << " " << symbols[i];
+ else
+ osstr << std::fixed << setprecision(2) << result << " " << symbols[i];
+
+ out = osstr.str();
+}
+
+/*!
+ *Browse a directory printing its contents in an HTML file.
+ *\param td The current thread context.
+ *\param s The current connection structure.
+ *\param directory Directory to show.
+ *\param cgi non used.
+ *\param onlyHeader Specify if send only the HTTP header.
+*/
+int HttpDir::send(HttpThreadContext* td, ConnectionPtr s,
+ const char* directory, const char* /*cgi*/,
+ int /*execute*/, int onlyHeader)
+{
+ u_long nbw;
+ string filename;
+ int ret;
+ FindData fd;
+ FiltersChain chain;
+ int lastSlash = 0;
+ bool useChunks = false;
+ u_long sentData = 0;
+ int i;
+ char fileTime[32];
+ char* bufferloop;
+ const char* browseDirCSSpath;
+ bool keepalive = false;
+ vector<HttpDir::FileStruct> files;
+ size_t sortIndex;
+ char sortType;
+ bool sortReverse = false;
+ HttpRequestHeader::Entry *host = td->request.other.get("Host");
+
+
+ chain.setProtocol(td->http);
+ chain.setProtocolData(td);
+ chain.setStream(td->connection->socket);
+ if(td->mime && Server::getInstance()->getFiltersFactory()->chain(&chain,
+ td->mime->filters,
+ td->connection->socket, &nbw, 1))
+ {
+ td->connection->host->warningsLogRequestAccess(td->id);
+ td->connection->host->warningsLogWrite("HttpDir: Error loading filters");
+ td->connection->host->warningsLogTerminateAccess(td->id);
+ chain.clearAllFilters();
+ return td->http->raiseHTTPError(500);
+ }
+
+ lastSlash = td->request.uri.rfind('/') + 1;
+
+ checkDataChunks(td, &keepalive, &useChunks);
+
+ td->response.contentType.assign("text/html");
+
+ if(!td->appendOutputs)
+ {
+
+ HttpHeaders::buildHTTPResponseHeader(td->buffer->getBuffer(),
+ &(td->response));
+
+ if(s->socket->send(td->buffer->getBuffer(),
+ (u_long)strlen(td->buffer->getBuffer()), 0)
+ == SOCKET_ERROR)
+ {
+ /* Remove the connection. */
+ return 0;
+ }
+ }
+
+ if(onlyHeader)
+ return 1;
+
+
+ sortIndex = td->request.uriOpts.find("sort=");
+
+ if(sortIndex != string::npos && sortIndex + 5 < td->request.uriOpts.length())
+ {
+ sortType = td->request.uriOpts.at(sortIndex + 5);
+ }
+
+ if(sortIndex != string::npos && sortIndex + 6 < td->request.uriOpts.length())
+ {
+ sortReverse = td->request.uriOpts.at(sortIndex + 6) == 'I';
+ }
+
+ /* Make sortType always lowercase. */
+ switch(sortType)
+ {
+ case 's':
+ case 'S':
+ sortType = 's';
+ break;
+ case 't':
+ case 'T':
+ sortType = 't';
+ break;
+ default:
+ sort (files.begin(), files.end(), compareFileStructByName);
+ }
+
+ browseDirCSSpath = td->http->getBrowseDirCSSFile();
+
+ td->buffer2->setLength(0);
+ *td->buffer2 << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\r\n"
+ "\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\r\n"
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">"
+ "\r\n<head>\r\n<title>" ;
+ *td->buffer2 << td->request.uri.c_str() ;
+ *td->buffer2 << "</title>\r\n";
+
+ /*
+ *If it is defined a CSS file for the graphic layout of
+ *the browse directory insert it in the page.
+ */
+ if(browseDirCSSpath != 0)
+ {
+ *td->buffer2 << "<link rel=\"stylesheet\" href=\""
+ << browseDirCSSpath
+ << "\" type=\"text/css\" media=\"all\"/>\r\n";
+ }
+
+
+ *td->buffer2 << "</head>\r\n";
+
+ ret = appendDataToHTTPChannel(td, td->buffer2->getBuffer(),
+ td->buffer2->getLength(),
+ &(td->outputData), &chain,
+ td->appendOutputs, useChunks);
+ if(ret)
+ {
+ /* Return an internal server error. */
+ td->outputData.closeFile();
+ chain.clearAllFilters();
+ return td->http->raiseHTTPError(500);
+ }
+
+ sentData = td->buffer2->getLength();
+
+ browseDirCSSpath = td->http->getBrowseDirCSSFile();
+
+ filename = directory;
+ td->buffer2->setLength(0);
+ *td->buffer2 << "<body>\r\n<h1>Contents of directory ";
+ *td->buffer2 << &td->request.uri[lastSlash] ;
+ *td->buffer2 << "</h1>\r\n<hr />\r\n";
+
+ ret = appendDataToHTTPChannel(td, td->buffer2->getBuffer(),
+ td->buffer2->getLength(),
+ &(td->outputData), &chain,
+ td->appendOutputs, useChunks);
+
+ if(ret)
+ {
+ td->outputData.closeFile();
+ /* Return an internal server error. */
+ return td->http->raiseHTTPError(500);
+ }
+ sentData += td->buffer2->getLength();
+
+ ret = fd.findfirst(filename.c_str());
+
+ if(ret == -1)
+ {
+ chain.clearAllFilters();
+ return td->http->raiseHTTPError(404);
+ }
+
+ /*
+ *With the current code we build the HTML TABLE to indicize the
+ *files in the directory.
+ */
+ td->buffer2->setLength(0);
+ *td->buffer2 << "<table width=\"100%\">\r\n<tr>\r\n" ;
+
+ if(sortType == 'f' && !sortReverse)
+ *td->buffer2 << "<th><a href=\"?sort=fI\">File</a></th>\r\n";
+ else
+ *td->buffer2 << "<th><a href=\"?sort=f\">File</a></th>\r\n";
+
+ if(sortType == 't' && !sortReverse)
+ *td->buffer2 << "<th><a href=\"?sort=tI\">Last Modified</a></th>\r\n";
+ else
+ *td->buffer2 << "<th><a href=\"?sort=t\">Last Modified</a></th>\r\n";
+
+ if(sortType == 's' && !sortReverse)
+ *td->buffer2 << "<th><a href=\"?sort=sI\">Size</a></th>\r\n</tr>\r\n";
+ else
+ *td->buffer2 << "<th><a href=\"?sort=s\">Size</a></th>\r\n</tr>\r\n";
+
+ ret = appendDataToHTTPChannel(td, td->buffer2->getBuffer(),
+ td->buffer2->getLength(),
+ &(td->outputData), &chain,
+ td->appendOutputs, useChunks);
+
+ if(ret)
+ {
+ td->outputData.closeFile();
+ chain.clearAllFilters();
+ /* Return an internal server error. */
+ return td->http->raiseHTTPError(500);
+ }
+
+ sentData += td->buffer2->getLength();
+
+ td->buffer2->setLength(0);
+
+ if(FilesUtility::getPathRecursionLevel(td->request.uri) >= 1)
+ {
+ string file;
+ file.assign(td->request.uri);
+ file.append("/../");
+
+ *td->buffer2 << "<tr>\r\n<td colspan=\"2\">"
+ << "<a href=\""
+ << (td->request.uriEndsWithSlash ? ".." : ".")
+ << "\">[ .. ]</a></td>\n"
+ << "<td>[directory]</td></tr>\r\n";
+
+ ret = appendDataToHTTPChannel(td, td->buffer2->getBuffer(),
+ td->buffer2->getLength(),
+ &(td->outputData), &chain,
+ td->appendOutputs, useChunks);
+ if(ret)
+ {
+ fd.findclose();
+ td->outputData.closeFile();
+ chain.clearAllFilters();
+ /* Return an internal server error. */
+ return td->http->raiseHTTPError(500);
+ }
+ sentData += td->buffer2->getLength();
+ }
+
+ /* Put all files in a vector. */
+ do
+ {
+ if(fd.name[0] == '.')
+ continue;
+ /* Do not show the security file. */
+ if(!strcmp(fd.name, "security"))
+ continue;
+
+ FileStruct file;
+ file.name.assign(fd.name);
+ file.time_write = fd.time_write;
+ file.attrib = fd.attrib;
+ file.size = fd.size;
+ files.push_back(file);
+
+ }
+ while(!fd.findnext());
+
+ fd.findclose();
+
+ /* Sort the vector. */
+ switch(sortType)
+ {
+ case 's':
+ sort (files.begin(), files.end(), compareFileStructBySize);
+ break;
+ case 't':
+ sort (files.begin(), files.end(), compareFileStructByTime);
+ break;
+ case 'f':
+ sort (files.begin(), files.end(), compareFileStructByName);
+ }
+
+ if(sortReverse)
+ reverse (files.begin(), files.end());
+
+ /* Build the files table and send it. */
+ for(vector<FileStruct>::iterator it = files.begin();
+ it != files.end(); it++)
+ {
+ string formattedName;
+
+ FileStruct& file = *it;
+
+ td->buffer2->setLength(0);
+
+ *td->buffer2 << "<tr>\r\n<td><a href=\"";
+ if(!td->request.uriEndsWithSlash)
+ {
+ *td->buffer2 << &td->request.uri[lastSlash];
+ *td->buffer2 << "/" ;
+ }
+ formattedName.assign(file.name);
+
+ formatHtml(file.name, formattedName);
+
+ *td->buffer2 << formattedName ;
+ *td->buffer2 << "\">" ;
+ *td->buffer2 << formattedName;
+ *td->buffer2 << "</a></td>\r\n<td>";
+
+ getRFC822GMTTime(file.time_write, fileTime, 32);
+
+ *td->buffer2 << fileTime ;
+ *td->buffer2 << "</td>\r\n<td>";
+
+ if(file.attrib & FILE_ATTRIBUTE_DIRECTORY)
+ {
+ *td->buffer2 << "[directory]";
+ }
+ else
+ {
+ string out;
+ getFormattedSize(file.size, out);
+ *td->buffer2 << out;
+ }
+
+ *td->buffer2 << "</td>\r\n</tr>\r\n";
+ ret = appendDataToHTTPChannel(td, td->buffer2->getBuffer(),
+ td->buffer2->getLength(),
+ &(td->outputData), &chain,
+ td->appendOutputs, useChunks);
+ if(ret)
+ {
+ td->outputData.closeFile();
+ chain.clearAllFilters();
+ /* Return an internal server error. */
+ return td->http->raiseHTTPError(500);
+ }
+
+ sentData += td->buffer2->getLength();
+
+ }
+
+ td->buffer2->setLength(0);
+ *td->buffer2 << "</table>\r\n<hr />\r\n<address>GNU MyServer "
+ << versionOfSoftware;
+
+ if(host && host->value->length())
+ {
+ ostringstream portBuff;
+ size_t portSeparator = host->value->find(':');
+ *td->buffer2 << " on ";
+ if(portSeparator != string::npos)
+ *td->buffer2 << host->value->substr(0, portSeparator).c_str() ;
+ else
+ *td->buffer2 << host->value->c_str() ;
+
+ *td->buffer2 << " Port ";
+ portBuff << td->connection->getLocalPort();
+ *td->buffer2 << portBuff.str();
+ }
+ *td->buffer2 << "</address>\r\n</body>\r\n</html>\r\n";
+ ret = appendDataToHTTPChannel(td, td->buffer2->getBuffer(),
+ td->buffer2->getLength(),
+ &(td->outputData), &chain,
+ td->appendOutputs, useChunks);
+
+ if(ret)
+ {
+ td->outputData.closeFile();
+ /* Return an internal server error. */
+ return td->http->raiseHTTPError(500);
+ }
+ sentData += td->buffer2->getLength();
+
+ *td->buffer2 << end_str;
+ /* Changes the \ character in the / character. */
+ bufferloop = td->buffer2->getBuffer();
+ while(*bufferloop++)
+ if(*bufferloop == '\\')
+ *bufferloop = '/';
+
+ if(!td->appendOutputs && useChunks)
+ {
+ if(chain.write("0\r\n\r\n", 5, &nbw))
+ return 1;
+ }
+
+ /* For logging activity. */
+ td->sentData += sentData;
+
+ chain.clearAllFilters();
+ return 1;
+
+}
+
+/*!
+ *Format a string to html.
+ *\param name String to convert.
+ *\param out HTML converted string.
+ */
+void HttpDir::formatHtml(string& in, string& out)
+{
+ string::size_type pos = 0;
+ out.assign(in);
+ /*
+ *Replace characters in the ranges 32-65 91-96 123-126 160-255
+ *with "&#CODE;".
+ */
+ for(pos = 0; out[pos] != '\0'; pos++)
+ {
+ if(((u_char)out[pos] >= 32 &&
+ (u_char)out[pos] <= 65) ||
+ ((u_char)out[pos] >= 91 &&
+ (u_char)out[pos] <= 96) ||
+ ((u_char)out[pos] >= 123 &&
+ (u_char)out[pos] <= 126) ||
+ ((u_char)out[pos] >= 160 &&
+ (u_char)out[pos] < 255))
+ {
+ ostringstream os;
+ os << "&#" << (int)((unsigned char)out[pos]) << ";";
+ out.replace(pos, 1, os.str());
+ pos += os.str().length() - 1;
+ }
+ }
+}
Copied: trunk/myserver/src/http_handler/http_file/http_file.cpp (from rev 2774,
trunk/myserver/src/protocol/http/http_file.cpp)
===================================================================
--- trunk/myserver/src/http_handler/http_file/http_file.cpp
(rev 0)
+++ trunk/myserver/src/http_handler/http_file/http_file.cpp 2008-09-02
19:00:55 UTC (rev 2780)
@@ -0,0 +1,627 @@
+/*
+MyServer
+Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#include <include/protocol/http/http.h>
+#include <include/protocol/http/http_headers.h>
+#include <include/http_handler/http_file/http_file.h>
+#include <include/filter/gzip/gzip.h>
+#include <include/server/server.h>
+#include <include/filter/filters_chain.h>
+
+#include <sstream>
+#include <algorithm>
+using namespace std;
+
+extern "C"
+{
+#ifdef WIN32
+#include <direct.h>
+#include <errno.h>
+#endif
+
+#ifdef NOT_WIN
+#include <string.h>
+#include <errno.h>
+#ifdef SENDFILE
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/sendfile.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#endif
+#endif
+}
+
+/*!
+ *Send a file to the client using the HTTP protocol.
+ *\param td The current HTTP thread context.
+ *\param s A pointer to the connection.
+ *\param filenamePath The path of the static file to send.
+ *\param exec Not used.
+ *\param onlyHeader Specify if send only the HTTP header.
+ */
+int HttpFile::send(HttpThreadContext* td, ConnectionPtr s,
+ const char *filenamePath, const char* /*exec*/,
+ int /*execute*/, int onlyHeader)
+{
+ /*
+ *With this routine we send a file through the HTTP protocol.
+ *Open the file and save its handle.
+ */
+ int ret;
+
+ /*
+ *Will we use GZIP compression to send data?
+ */
+ bool useGzip = false;
+ u_long filesize = 0;
+ File *file = 0;
+ u_long bytesToSend;
+ u_long firstByte = td->request.rangeByteBegin;
+ u_long lastByte = td->request.rangeByteEnd;
+ bool keepalive = false;
+ bool useChunks = false;
+ bool useModifiers = false;
+ MemoryStream memStream(td->buffer2);
+ FiltersChain chain;
+ u_long nbw;
+ u_long nbr;
+
+ u_long dataSent = 0;
+
+ try
+ {
+ file = Server::getInstance()->getCachedFiles()->open(filenamePath);
+ if(file == 0)
+ {
+ return td->http->raiseHTTPError(500);
+ }
+ /*
+ *Check how many bytes are ready to be send.
+ */
+ filesize = file->getFileSize();
+ bytesToSend = filesize;
+ if(lastByte == 0)
+ {
+ lastByte = bytesToSend;
+ }
+ else
+ {
+ /*
+ *If the client use ranges set the right value
+ *for the last byte number.
+ */
+ lastByte = std::min(lastByte + 1, bytesToSend);
+ }
+
+ /*
+ * bytesToSend is the interval between the first and the last byte.
+ */
+ bytesToSend = lastByte - firstByte;
+
+ /*
+ * If fail to set the file pointer returns an internal server error.
+ */
+ ret = file->setFilePointer(firstByte);
+ if(ret)
+ {
+ file->closeFile();
+ delete file;
+ return td->http->raiseHTTPError(500);
+ }
+
+
+ {
+ /*
+ *Use GZIP compression to send files bigger than GZIP threshold.
+ */
+ const char* val = s->host->getHashedData("GZIP_THRESHOLD");
+ useGzip = false;
+ if(val)
+ {
+ u_long gzipThreshold = atoi(val);
+ if(bytesToSend >= gzipThreshold)
+ useGzip = true;
+ }
+
+ }
+
+ keepalive = td->request.isKeepAlive();
+
+#ifndef DO_NOT_USEGZIP
+ /*
+ *Be sure that the client accept GZIP compressed data.
+ */
+ if(useGzip)
+ {
+ HttpRequestHeader::Entry* e = td->request.other.get("Accept-Encoding");
+ if(e)
+ {
+ useGzip &= (e->value->find("gzip") != string::npos);
+ }
+ else
+ useGzip = false;
+
+ }
+#else
+ /*
+ * If compiled without GZIP support force the server to don't use it.
+ */
+ useGzip = false;
+#endif
+ if(td->appendOutputs)
+ useGzip = false;
+
+ td->buffer->setLength(0);
+
+ /* If a Range was requested send 206 and not 200 for success. */
+ if( td->request.rangeByteBegin || td->request.rangeByteEnd )
+ {
+ HttpResponseHeader::Entry *e;
+ ostringstream buffer;
+ td->response.httpStatus = 206;
+ buffer << "bytes "<< (u_long)firstByte << "-"
+ << (u_long)lastByte << "/" << (u_long)filesize ;
+
+ e = td->response.other.get("Content-Range");
+ if(e)
+ e->value->assign(buffer.str());
+ else
+ {
+ e = new HttpResponseHeader::Entry();
+ e->name->assign("Content-Range");
+ e->value->assign(buffer.str());
+ td->response.other.put(*(e->name), e);
+ }
+
+
+ e = td->response.other.get("Transfer-Encoding");
+ if(e)
+ e->value->assign("chunked");
+ else
+ {
+ e = new HttpResponseHeader::Entry();
+ e->name->assign("Transfer-Encoding");
+ e->value->assign("chunked");
+ td->response.other.put(*(e->name), e);
+ }
+
+ useGzip = false;
+ }
+ chain.setProtocol(td->http);
+ chain.setProtocolData(td);
+ chain.setStream(&memStream);
+ if(td->mime)
+ {
+ if(td->mime &&
+ Server::getInstance()->getFiltersFactory()->chain(&chain,
+ td->mime->filters,
+ &memStream,
+ &nbw))
+ {
+ file->closeFile();
+ delete file;
+ chain.clearAllFilters();
+ return 0;
+ }
+ memStream.refresh();
+
+ dataSent += nbw;
+ }
+
+ if(useGzip && !chain.isFilterPresent("gzip"))
+ {
+ Filter* gzipFilter =
+ Server::getInstance()->getFiltersFactory()->getFilter("gzip");
+ u_long nbw;
+ if(!gzipFilter)
+ {
+ file->closeFile();
+ delete file;
+ chain.clearAllFilters();
+ return 0;
+ }
+ if(chain.addFilter(gzipFilter, &nbw))
+ {
+ delete gzipFilter;
+ file->closeFile();
+ delete file;
+ chain.clearAllFilters();
+ return 0;
+ }
+ dataSent += nbw;
+ }
+
+ useModifiers = chain.hasModifiersFilters();
+
+ if(keepalive && !useModifiers)
+ {
+ ostringstream buffer;
+ buffer << (u_int)bytesToSend;
+ td->response.contentLength.assign(buffer.str());
+ }
+
+ /* Specify the connection type. */
+ if(keepalive)
+ {
+ td->response.connection.assign("keep-alive");
+ }
+ else
+ {
+ td->response.connection.assign("close");
+ }
+
+ if(useModifiers)
+ {
+ string s;
+ HttpResponseHeader::Entry *e;
+ chain.getName(s);
+ e = td->response.other.get("Content-Encoding");
+ if(e)
+ e->value->assign(s);
+ else
+ {
+ e = new HttpResponseHeader::Entry();
+ e->name->assign("Content-Encoding");
+ e->value->assign(s);
+ td->response.other.put(*(e->name), e);
+ }
+ /* Do not use chunked transfer with old HTTP/1.0 clients. */
+ if(keepalive)
+ {
+ HttpResponseHeader::Entry *e;
+ e = td->response.other.get("Transfer-Encoding");
+ if(e)
+ e->value->assign("chunked");
+ else
+ {
+ e = new HttpResponseHeader::Entry();
+ e->name->assign("Transfer-Encoding");
+ e->value->assign("chunked");
+ td->response.other.put(*(e->name), e);
+ }
+
+ useChunks = true;
+ }
+ }
+
+ HttpHeaders::buildHTTPResponseHeader(td->buffer->getBuffer(),
+ &td->response);
+ td->buffer->setLength((u_long)strlen(td->buffer->getBuffer()));
+ if(!td->appendOutputs)
+ {
+ /* Send the HTTP header. */
+ if(s->socket->send(td->buffer->getBuffer(),
+ (u_long)td->buffer->getLength(), 0) == SOCKET_ERROR)
+ {
+ file->closeFile();
+ delete file;
+ chain.clearAllFilters();
+ return 1;
+ }
+ }
+
+ /*
+ *If is requested only the header exit from the function;
+ *used by the HEAD request.
+ */
+ if(onlyHeader)
+ {
+ file->closeFile();
+ delete file;
+ chain.clearAllFilters();
+ return 0;
+ }
+
+#ifdef SENDFILE
+ /*
+ * Check if there are all the conditions to use a direct copy from the
+ * file to the socket. The sendfile syscall copy from a descriptor to
+ * another directly in the kernel space without performs an extra copy
+ * to an userspace buffer.
+ */
+ if(!useChunks && chain.isEmpty() &&
+ !td->appendOutputs && (file->getHandle() != -1) &&
+ !(td->http->getProtocolOptions() & PROTOCOL_USES_SSL))
+ {
+ off_t offset = firstByte;
+ ret = sendfile(s->socket->getHandle(), file->getHandle(),
+ &offset, bytesToSend);
+ file->closeFile();
+ delete file;
+ chain.clearAllFilters();
+
+ /* For logging activity. */
+ td->sentData += ret;
+
+ return 0;
+ }
+#endif
+
+ if(td->appendOutputs)
+ chain.setStream(&(td->outputData));
+ else
+ chain.setStream(s->socket);
+
+ /*
+ *Flush initial data. This is data that filters could have added
+ *and we have to send before the file itself, for example the gzip
+ *filter add a header to file.
+ */
+ if(memStream.availableToRead())
+ {
+ ret = memStream.read(td->buffer->getBuffer(),
+ td->buffer->getRealLength(),
+ &nbr);
+
+ if(ret)
+ {
+ file->closeFile();
+ delete file;
+ chain.clearAllFilters();
+ return 0;
+ }
+
+ memStream.refresh();
+
+ if(nbr)
+ {
+ if(HttpDataHandler::appendDataToHTTPChannel(td,
+ td->buffer->getBuffer(),
+ nbr,
+ &(td->outputData),
+ chain.getStream(),
+ td->appendOutputs,
+ useChunks))
+ {
+ file->closeFile();
+ delete file;
+ chain.clearAllFilters();
+ return 1;
+ dataSent += nbw;
+ }
+ } /* nbr. */
+ } /* memStream.availableToRead(). */
+
+
+ /* Flush the rest of the file. */
+ for(;;)
+ {
+ u_long nbr;
+ u_long nbw;
+
+ /* Check if there are other bytes to send. */
+ if(bytesToSend)
+ {
+ /* Read from the file the bytes to send. */
+ ret = file->readFromFile(td->buffer->getBuffer(),
+ std::min(static_cast<u_long>(bytesToSend),
+
static_cast<u_long>(td->buffer->getRealLength()/2)),
+ &nbr);
+ if(ret)
+ break;
+
+ if(nbr == 0)
+ {
+ bytesToSend = 0;
+ continue;
+ }
+
+ bytesToSend -= nbr;
+
+
+ ret = appendDataToHTTPChannel(td, td->buffer->getBuffer(),
+ nbr,
+ &(td->outputData),
+ &chain,
+ td->appendOutputs,
+ useChunks,
+ td->buffer->getRealLength(),
+ &memStream);
+ if(ret)
+ break;
+
+ dataSent += nbr;
+ }
+ else /* if(bytesToSend) */
+ {
+ /* If we don't use chunks we can flush directly. */
+ if(!useChunks)
+ {
+ ret = chain.flush(&nbw);
+
+ break;
+ }
+ else
+ {
+ /*
+ *Replace the final stream before the flush and write to a
+ *memory buffer, after all the data is flushed from the
+ *chain we can replace the stream with the original one and
+ *write there the HTTP data chunk.
+ */
+ Stream* tmpStream = chain.getStream();
+
+ chain.setStream(&memStream);
+
+ memStream.refresh();
+
+ ret = chain.flush(&nbw);
+
+ if(ret)
+ break;
+
+ chain.setStream(tmpStream);
+
+ ret = memStream.read(td->buffer->getBuffer(),
+ td->buffer->getRealLength(),
+ &nbr);
+ if(ret)
+ break;
+
+ ret = HttpDataHandler::appendDataToHTTPChannel(td,
+
td->buffer->getBuffer(),
+ nbr,
+ &(td->outputData),
+ chain.getStream(),
+ td->appendOutputs,
+ useChunks);
+ if(ret)
+ break;
+
+ ret = HttpDataHandler::appendDataToHTTPChannel(td,
+ 0,
+ 0,
+ &(td->outputData),
+ chain.getStream(),
+ td->appendOutputs,
+ useChunks);
+
+ break;
+ }
+ }
+
+ memStream.refresh();
+
+ }/* End for loop. */
+
+ file->closeFile();
+ delete file;
+ }
+ catch(bad_alloc &ba)
+ {
+ file->closeFile();
+ delete file;
+ s->host->warningsLogRequestAccess(td->id);
+ s->host->warningsLogWrite("HttpFile: Error allocating memory");
+ s->host->warningsLogTerminateAccess(td->id);
+ chain.clearAllFilters();
+ return td->http->raiseHTTPError(500);
+ }
+ catch(...)
+ {
+ file->closeFile();
+ delete file;
+ s->host->warningsLogRequestAccess(td->id);
+ s->host->warningsLogWrite("HttpFile: Internal error");
+ s->host->warningsLogTerminateAccess(td->id);
+ chain.clearAllFilters();
+ return td->http->raiseHTTPError(500);
+ };
+
+ /* For logging activity. */
+ td->sentData += dataSent;
+
+ chain.clearAllFilters();
+ return !ret;
+}
+
+/*!
+ *Constructor for the class.
+ */
+HttpFile::HttpFile()
+{
+
+}
+
+/*!
+ *Destroy the object.
+ */
+HttpFile::~HttpFile()
+{
+
+}
+
+/*!
+ *Load the static elements.
+ *\param confFile Not used.
+ */
+int HttpFile::load(XmlParser* /*confFile*/)
+{
+ return 0;
+}
+
+/*!
+ *Unload the static elements.
+ */
+int HttpFile::unLoad()
+{
+ return 0;
+}
+
+/*!
+ *Custom version for the appendDataToHTTPChannel function, this is
+ *slower that the HttpDataHandler one but the internal buffer is
+ *needed by the filters chain.
+ *\param td The HTTP thread context.
+ *\param buffer Data to send.
+ *\param size Size of the buffer.
+ *\param appendFile The file where append if in append mode.
+ *\param chain Where send data if not append.
+ *\param append Append to the file?
+ *\param useChunks Can we use HTTP chunks to send data?
+ *\param realBufferSize The real dimension of the buffer that can be
+ *used by this method.
+ *\param tmpStream A support on memory read/write stream used
+ *internally by the function.
+ */
+int HttpFile::appendDataToHTTPChannel(HttpThreadContext* td,
+ char* buffer,
+ u_long size,
+ File* appendFile,
+ FiltersChain* chain,
+ bool append,
+ bool useChunks,
+ u_long realBufferSize,
+ MemoryStream *tmpStream)
+{
+ u_long nbr, nbw;
+ Stream *oldStream = chain->getStream();
+
+ /*
+ *This function can't append directly to the chain because we can't
+ *know in advance the data chunk size. Therefore we replace the
+ *final stream with a memory buffer and write there the final data
+ *chunk content, finally we read from it and send directly on the
+ *original stream.
+ */
+ chain->setStream(tmpStream);
+
+ if(chain->write(buffer, size, &nbw))
+ return 1;
+
+ if(tmpStream->read(buffer, realBufferSize, &nbr))
+ return 1;
+
+ chain->setStream(oldStream);
+
+ /*
+ *Use of chain->getStream() is needed to write directly on the
+ *final stream.
+ */
+ return HttpDataHandler::appendDataToHTTPChannel(td,
+ buffer,
+ nbr,
+ appendFile,
+ chain->getStream(),
+ append,
+ useChunks);
+
+}
Modified: trunk/myserver/src/http_handler/isapi/isapi.cpp
===================================================================
--- trunk/myserver/src/http_handler/isapi/isapi.cpp 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/src/http_handler/isapi/isapi.cpp 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -21,7 +21,7 @@
#include <include/server/server.h>
#include <include/base/file/file.h>
#include <include/base/file/files_utility.h>
-#include <include/env/env.h>
+#include <include/protocol/http/env/env.h>
#include <include/base/dynamic_lib/dynamiclib.h>
#include <string>
Modified: trunk/myserver/src/http_handler/mscgi/mscgi.cpp
===================================================================
--- trunk/myserver/src/http_handler/mscgi/mscgi.cpp 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/src/http_handler/mscgi/mscgi.cpp 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -19,7 +19,7 @@
#include <include/protocol/http/http.h>
#include <include/server/server.h>
#include <include/conf/security/security.h>
-#include <include/env/env.h>
+#include <include/protocol/http/env/env.h>
#include <include/base/base64/mime_utils.h>
#include <include/base/file/file.h>
#include <include/base/file/files_utility.h>
Modified: trunk/myserver/src/http_handler/scgi/scgi.cpp
===================================================================
--- trunk/myserver/src/http_handler/scgi/scgi.cpp 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/src/http_handler/scgi/scgi.cpp 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -15,7 +15,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <include/http_handler/scgi/scgi.h>
-#include <include/env/env.h>
+#include <include/protocol/http/env/env.h>
#include <include/protocol/http/http.h>
#include <include/base/string/stringutils.h>
#include <include/server/server.h>
Modified: trunk/myserver/src/plugin/executor/dynamic_executor.cpp
===================================================================
--- trunk/myserver/src/plugin/executor/dynamic_executor.cpp 2008-09-01
19:56:39 UTC (rev 2779)
+++ trunk/myserver/src/plugin/executor/dynamic_executor.cpp 2008-09-02
19:00:55 UTC (rev 2780)
@@ -19,7 +19,6 @@
#include <include/plugin/executor/dynamic_executor.h>
#include <include/base/xml/xml_parser.h>
#include <include/server/server.h>
-#include <include/find_data/find_data.h>
#include <include/base/file/file.h>
#include <string>
Modified: trunk/myserver/src/plugin/filter/dyn_filter.cpp
===================================================================
--- trunk/myserver/src/plugin/filter/dyn_filter.cpp 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/src/plugin/filter/dyn_filter.cpp 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -19,7 +19,7 @@
#include <include/filter/stream.h>
#include <include/filter/filter.h>
#include <include/plugin/filter/dyn_filter.h>
-#include <include/find_data/find_data.h>
+#include <include/base/find_data/find_data.h>
#include <include/server/server.h>
#include <string>
#include <sstream>
Modified: trunk/myserver/src/plugin/filter/dyn_filter_file.cpp
===================================================================
--- trunk/myserver/src/plugin/filter/dyn_filter_file.cpp 2008-09-01
19:56:39 UTC (rev 2779)
+++ trunk/myserver/src/plugin/filter/dyn_filter_file.cpp 2008-09-02
19:00:55 UTC (rev 2780)
@@ -19,7 +19,6 @@
#include <include/filter/stream.h>
#include <include/filter/filter.h>
#include <include/plugin/filter/dyn_filter_file.h>
-#include <include/find_data/find_data.h>
#include <include/server/server.h>
#include <string>
#include <sstream>
Modified: trunk/myserver/src/plugin/filter/dyn_filters_manager.cpp
===================================================================
--- trunk/myserver/src/plugin/filter/dyn_filters_manager.cpp 2008-09-01
19:56:39 UTC (rev 2779)
+++ trunk/myserver/src/plugin/filter/dyn_filters_manager.cpp 2008-09-02
19:00:55 UTC (rev 2780)
@@ -19,7 +19,7 @@
#include <include/filter/stream.h>
#include <include/filter/filter.h>
#include <include/plugin/filter/dyn_filter.h>
-#include <include/find_data/find_data.h>
+#include <include/base/find_data/find_data.h>
#include <include/server/server.h>
#include <include/plugin/filter/dyn_filters_manager.h>
#include <include/filter/filter.h>
Modified: trunk/myserver/src/plugin/generic_plugins_manager.cpp
===================================================================
--- trunk/myserver/src/plugin/generic_plugins_manager.cpp 2008-09-01
19:56:39 UTC (rev 2779)
+++ trunk/myserver/src/plugin/generic_plugins_manager.cpp 2008-09-02
19:00:55 UTC (rev 2780)
@@ -17,7 +17,6 @@
#include "stdafx.h"
#include <include/plugin/generic_plugins_manager.h>
-#include <include/find_data/find_data.h>
#include <include/base/xml/xml_parser.h>
#include <include/server/server.h>
#include <string>
Modified: trunk/myserver/src/plugin/http_command/dyn_http_command.cpp
===================================================================
--- trunk/myserver/src/plugin/http_command/dyn_http_command.cpp 2008-09-01
19:56:39 UTC (rev 2779)
+++ trunk/myserver/src/plugin/http_command/dyn_http_command.cpp 2008-09-02
19:00:55 UTC (rev 2780)
@@ -15,11 +15,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-
#include <include/plugin/http_command/dyn_http_command.h>
-#include <include/base/xml/xml_parser.h>
#include <include/server/server.h>
-#include <include/find_data/find_data.h>
#include <string>
Modified: trunk/myserver/src/plugin/http_manager/dyn_http_manager.cpp
===================================================================
--- trunk/myserver/src/plugin/http_manager/dyn_http_manager.cpp 2008-09-01
19:56:39 UTC (rev 2779)
+++ trunk/myserver/src/plugin/http_manager/dyn_http_manager.cpp 2008-09-02
19:00:55 UTC (rev 2780)
@@ -19,7 +19,6 @@
#include <include/plugin/http_manager/dyn_http_manager.h>
#include <include/base/xml/xml_parser.h>
#include <include/server/server.h>
-#include <include/find_data/find_data.h>
#include <string>
Modified: trunk/myserver/src/plugin/http_manager/dyn_http_manager_list.cpp
===================================================================
--- trunk/myserver/src/plugin/http_manager/dyn_http_manager_list.cpp
2008-09-01 19:56:39 UTC (rev 2779)
+++ trunk/myserver/src/plugin/http_manager/dyn_http_manager_list.cpp
2008-09-02 19:00:55 UTC (rev 2780)
@@ -16,11 +16,9 @@
*/
-#include <include/plugin/http_manager/dyn_http_manager.h>
#include <include/plugin/http_manager/dyn_http_manager_list.h>
-#include <include/base/xml/xml_parser.h>
+#include <include/plugin/http_manager/dyn_http_manager.h>
#include <include/server/server.h>
-#include <include/find_data/find_data.h>
#include <string>
Modified: trunk/myserver/src/plugin/plugins_namespace_manager.cpp
===================================================================
--- trunk/myserver/src/plugin/plugins_namespace_manager.cpp 2008-09-01
19:56:39 UTC (rev 2779)
+++ trunk/myserver/src/plugin/plugins_namespace_manager.cpp 2008-09-02
19:00:55 UTC (rev 2780)
@@ -17,7 +17,7 @@
#include "stdafx.h"
#include <include/plugin/plugins_namespace_manager.h>
-#include <include/find_data/find_data.h>
+#include <include/base/find_data/find_data.h>
#include <include/base/xml/xml_parser.h>
#include <include/server/server.h>
#include <string>
Modified: trunk/myserver/src/plugin/protocol/dynamic_protocol.cpp
===================================================================
--- trunk/myserver/src/plugin/protocol/dynamic_protocol.cpp 2008-09-01
19:56:39 UTC (rev 2779)
+++ trunk/myserver/src/plugin/protocol/dynamic_protocol.cpp 2008-09-02
19:00:55 UTC (rev 2780)
@@ -19,7 +19,6 @@
#include <include/plugin/protocol/protocols_manager.h>
#include <include/base/xml/xml_parser.h>
#include <include/server/server.h>
-#include <include/find_data/find_data.h>
#include <string>
Modified: trunk/myserver/src/plugin/protocol/protocols_manager.cpp
===================================================================
--- trunk/myserver/src/plugin/protocol/protocols_manager.cpp 2008-09-01
19:56:39 UTC (rev 2779)
+++ trunk/myserver/src/plugin/protocol/protocols_manager.cpp 2008-09-02
19:00:55 UTC (rev 2780)
@@ -19,7 +19,6 @@
#include <include/plugin/protocol/protocols_manager.h>
#include <include/base/xml/xml_parser.h>
#include <include/server/server.h>
-#include <include/find_data/find_data.h>
#include <include/plugin/protocol/dynamic_protocol.h>
#include <string>
#include <algorithm>
Modified: trunk/myserver/src/protocol/control/control_header.cpp
===================================================================
--- trunk/myserver/src/protocol/control/control_header.cpp 2008-09-01
19:56:39 UTC (rev 2779)
+++ trunk/myserver/src/protocol/control/control_header.cpp 2008-09-02
19:00:55 UTC (rev 2780)
@@ -32,10 +32,6 @@
#endif
}
-#ifdef NOT_WIN
-#include <include/find_data/find_data.h>
-#endif
-
/*!
*Return a string containing options specified by the client.
*/
Modified: trunk/myserver/src/protocol/control/control_protocol.cpp
===================================================================
--- trunk/myserver/src/protocol/control/control_protocol.cpp 2008-09-01
19:56:39 UTC (rev 2779)
+++ trunk/myserver/src/protocol/control/control_protocol.cpp 2008-09-02
19:00:55 UTC (rev 2780)
@@ -20,7 +20,7 @@
#include <include/base/xml/xml_parser.h>
#include <include/base/md5/md5.h>
#include <include/server/server.h>
-#include <include/find_data/find_data.h>
+#include <include/base/find_data/find_data.h>
#include <include/plugin/protocol/protocols_manager.h>
#include <include/protocol/control/control_errors.h>
#include <include/base/string/stringutils.h>
@@ -45,9 +45,6 @@
extern const char *versionOfSoftware;
-#include <include/find_data/find_data.h>
-
-
char ControlProtocol::adminLogin[64] = "";
char ControlProtocol::adminPassword[64] = "";
int ControlProtocol::controlEnabled = 0;
Modified: trunk/myserver/src/protocol/ftp/ftp.cpp
===================================================================
--- trunk/myserver/src/protocol/ftp/ftp.cpp 2008-09-01 19:56:39 UTC (rev
2779)
+++ trunk/myserver/src/protocol/ftp/ftp.cpp 2008-09-02 19:00:55 UTC (rev
2780)
@@ -25,7 +25,7 @@
#include <include/base/file/files_utility.h>
#include <include/base/file/file.h>
#include <include/base/string/securestr.h>
-#include <include/find_data/find_data.h>
+#include <include/base/find_data/find_data.h>
#include <include/base/string/stringutils.h>
#include <include/base/mem_buff/mem_buff.h>
#include <assert.h>
Modified: trunk/myserver/src/protocol/http/Makefile.am
===================================================================
--- trunk/myserver/src/protocol/http/Makefile.am 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/src/protocol/http/Makefile.am 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -1,5 +1,5 @@
lib_LIBRARIES = libhttp.a
-libhttp_a_SOURCES = http.cpp http_data_handler.cpp http_data_read.cpp
http_dir.cpp http_errors.cpp http_file.cpp http_header_checker.cpp
http_headers.cpp http_request.cpp http_response.cpp http_thread_context.cpp
-SUBDIRS =
+libhttp_a_SOURCES = http.cpp http_data_handler.cpp http_data_read.cpp
http_errors.cpp http_header_checker.cpp http_headers.cpp http_request.cpp
http_response.cpp http_thread_context.cpp
+SUBDIRS = env
INCLUDES = $(all_includes)
Copied: trunk/myserver/src/protocol/http/env (from rev 2774,
trunk/myserver/src/env)
Property changes on: trunk/myserver/src/protocol/http/env
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/myserver/src/protocol/http/env/env.cpp
===================================================================
--- trunk/myserver/src/env/env.cpp 2008-08-31 23:22:09 UTC (rev 2774)
+++ trunk/myserver/src/protocol/http/env/env.cpp 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -16,7 +16,7 @@
*/
#include "stdafx.h"
-#include <include/env/env.h>
+#include <include/protocol/http/env/env.h>
#include <include/protocol/http/http_headers.h>
#include <include/protocol/http/http.h>
#include <include/protocol/http/http_errors.h>
Modified: trunk/myserver/src/protocol/http/http.cpp
===================================================================
--- trunk/myserver/src/protocol/http/http.cpp 2008-09-01 19:56:39 UTC (rev
2779)
+++ trunk/myserver/src/protocol/http/http.cpp 2008-09-02 19:00:55 UTC (rev
2780)
@@ -36,8 +36,8 @@
#include <include/http_handler/scgi/scgi.h>
#include <include/http_handler/mscgi/mscgi.h>
#include <include/http_handler/isapi/isapi.h>
-#include <include/protocol/http/http_file.h>
-#include <include/protocol/http/http_dir.h>
+#include <include/http_handler/http_file/http_file.h>
+#include <include/http_handler/http_dir/http_dir.h>
#include <include/protocol/http/http_data_read.h>
#include <string>
@@ -58,10 +58,6 @@
#endif
}
-#ifdef NOT_WIN
-#include <include/find_data/find_data.h>
-#endif
-
static HttpStaticData staticHttp;
Modified: trunk/myserver/src/protocol/http/http_data_read.cpp
===================================================================
--- trunk/myserver/src/protocol/http/http_data_read.cpp 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/src/protocol/http/http_data_read.cpp 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -45,10 +45,6 @@
#endif
}
-#ifdef NOT_WIN
-#include <include/find_data/find_data.h>
-#endif
-
/*!
*Read primitive post data as it is sent by the client without apply any filter
*in a contiguous manner, first read from the memory buffer and after from the
Deleted: trunk/myserver/src/protocol/http/http_dir.cpp
===================================================================
--- trunk/myserver/src/protocol/http/http_dir.cpp 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/src/protocol/http/http_dir.cpp 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -1,572 +0,0 @@
-/*
-MyServer
-Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "stdafx.h"
-#include <include/server/server.h>
-#include <include/protocol/http/http.h>
-#include <include/protocol/http/http_headers.h>
-#include <include/protocol/http/http_dir.h>
-#include <include/filter/filters_chain.h>
-#include <include/base/file/files_utility.h>
-
-extern "C"
-{
-#ifdef WIN32
-#include <direct.h>
-#include <errno.h>
-#endif
-
-#ifdef NOT_WIN
-#include <string.h>
-#include <errno.h>
-#endif
-}
-
-#include <include/find_data/find_data.h>
-#include <include/base/string/stringutils.h>
-#ifdef NOT_WIN
-#endif
-
-#include <string>
-#include <sstream>
-#include <vector>
-#include <algorithm>
-#include <iomanip>
-
-using namespace std;
-
-/*!
- * Compare two HttpDir::FileStruct by their filename.
- */
-bool HttpDir::compareFileStructByName (HttpDir::FileStruct i,
HttpDir::FileStruct j)
-{
- return stringcmpi (i.name, j.name) < 0 ? true : false;
-}
-
-/*!
- * Compare two HttpDir::FileStruct by their last modified file time.
- */
-
-bool HttpDir::compareFileStructByTime (HttpDir::FileStruct i,
HttpDir::FileStruct j)
-{
- return i.time_write < j.time_write;
-}
-
-/*!
- * Compare two HttpDir::FileStruct by their file size.
- */
-bool HttpDir::compareFileStructBySize (HttpDir::FileStruct i,
HttpDir::FileStruct j)
-{
- return i.size < j.size;
-}
-
-/*!
- *Constructor for the class.
- */
-HttpDir::HttpDir()
-{
-
-}
-
-/*!
- *Destroy the object.
- */
-HttpDir::~HttpDir()
-{
-
-}
-
-/*!
- *Load the static elements.
- */
-int HttpDir::load(XmlParser* /*confFile*/)
-{
- return 0;
-}
-
-/*!
- *Unload the static elements.
- */
-int HttpDir::unLoad()
-{
- return 0;
-}
-
-/*!
- *Get a formatted dobule representation of BYTES right shifted by POWER.
- *\param bytes Number of bytes.
- *\param power Power of 2.
- *\return the double representation for BYTES>>POWER.
- */
-double HttpDir::formatBytes(u_long bytes, u_int power)
-{
- const u_long quotient = bytes >> power;
- if (quotient == 0)
- return -1;
-
- const u_long unit = 1 << power;
- const u_long remainder = bytes & (unit - 1);
- const double result = quotient + static_cast<double>(remainder) / unit;
- return result;
-}
-
-
-/*!
- *Fullfill the string out with a formatted representation for bytes.
- *\param bytes Size to format.
- *\param out Out string.
- */
-void HttpDir::getFormattedSize(u_long bytes, string & out)
-{
- const string symbols[] = {"TB", "GB", "MB", "KB", "bytes"};
- const u_int powers[] = {40, 30, 20, 10, 0};
- double result;
- size_t i;
- ostringstream osstr;
-
- if (bytes == 0)
- {
- out = "0";
- return;
- }
-
- for (i = 0; i < sizeof (powers); i++)
- {
- result = formatBytes (bytes, powers[i]);
- if (result != -1)
- break;
- }
-
- if((result - floor(result)) < 0.01)
- osstr << std::fixed << setprecision(0) << result << " " << symbols[i];
- else
- osstr << std::fixed << setprecision(2) << result << " " << symbols[i];
-
- out = osstr.str();
-}
-
-/*!
- *Browse a directory printing its contents in an HTML file.
- *\param td The current thread context.
- *\param s The current connection structure.
- *\param directory Directory to show.
- *\param cgi non used.
- *\param onlyHeader Specify if send only the HTTP header.
-*/
-int HttpDir::send(HttpThreadContext* td, ConnectionPtr s,
- const char* directory, const char* /*cgi*/,
- int /*execute*/, int onlyHeader)
-{
- u_long nbw;
- string filename;
- int ret;
- FindData fd;
- FiltersChain chain;
- int lastSlash = 0;
- bool useChunks = false;
- u_long sentData = 0;
- int i;
- char fileTime[32];
- char* bufferloop;
- const char* browseDirCSSpath;
- bool keepalive = false;
- vector<HttpDir::FileStruct> files;
- size_t sortIndex;
- char sortType;
- bool sortReverse = false;
- HttpRequestHeader::Entry *host = td->request.other.get("Host");
-
-
- chain.setProtocol(td->http);
- chain.setProtocolData(td);
- chain.setStream(td->connection->socket);
- if(td->mime && Server::getInstance()->getFiltersFactory()->chain(&chain,
- td->mime->filters,
- td->connection->socket, &nbw, 1))
- {
- td->connection->host->warningsLogRequestAccess(td->id);
- td->connection->host->warningsLogWrite("HttpDir: Error loading filters");
- td->connection->host->warningsLogTerminateAccess(td->id);
- chain.clearAllFilters();
- return td->http->raiseHTTPError(500);
- }
-
- lastSlash = td->request.uri.rfind('/') + 1;
-
- checkDataChunks(td, &keepalive, &useChunks);
-
- td->response.contentType.assign("text/html");
-
- if(!td->appendOutputs)
- {
-
- HttpHeaders::buildHTTPResponseHeader(td->buffer->getBuffer(),
- &(td->response));
-
- if(s->socket->send(td->buffer->getBuffer(),
- (u_long)strlen(td->buffer->getBuffer()), 0)
- == SOCKET_ERROR)
- {
- /* Remove the connection. */
- return 0;
- }
- }
-
- if(onlyHeader)
- return 1;
-
-
- sortIndex = td->request.uriOpts.find("sort=");
-
- if(sortIndex != string::npos && sortIndex + 5 < td->request.uriOpts.length())
- {
- sortType = td->request.uriOpts.at(sortIndex + 5);
- }
-
- if(sortIndex != string::npos && sortIndex + 6 < td->request.uriOpts.length())
- {
- sortReverse = td->request.uriOpts.at(sortIndex + 6) == 'I';
- }
-
- /* Make sortType always lowercase. */
- switch(sortType)
- {
- case 's':
- case 'S':
- sortType = 's';
- break;
- case 't':
- case 'T':
- sortType = 't';
- break;
- default:
- sort (files.begin(), files.end(), compareFileStructByName);
- }
-
- browseDirCSSpath = td->http->getBrowseDirCSSFile();
-
- td->buffer2->setLength(0);
- *td->buffer2 << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
- "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\r\n"
- "\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\r\n"
- "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">"
- "\r\n<head>\r\n<title>" ;
- *td->buffer2 << td->request.uri.c_str() ;
- *td->buffer2 << "</title>\r\n";
-
- /*
- *If it is defined a CSS file for the graphic layout of
- *the browse directory insert it in the page.
- */
- if(browseDirCSSpath != 0)
- {
- *td->buffer2 << "<link rel=\"stylesheet\" href=\""
- << browseDirCSSpath
- << "\" type=\"text/css\" media=\"all\"/>\r\n";
- }
-
-
- *td->buffer2 << "</head>\r\n";
-
- ret = appendDataToHTTPChannel(td, td->buffer2->getBuffer(),
- td->buffer2->getLength(),
- &(td->outputData), &chain,
- td->appendOutputs, useChunks);
- if(ret)
- {
- /* Return an internal server error. */
- td->outputData.closeFile();
- chain.clearAllFilters();
- return td->http->raiseHTTPError(500);
- }
-
- sentData = td->buffer2->getLength();
-
- browseDirCSSpath = td->http->getBrowseDirCSSFile();
-
- filename = directory;
- td->buffer2->setLength(0);
- *td->buffer2 << "<body>\r\n<h1>Contents of directory ";
- *td->buffer2 << &td->request.uri[lastSlash] ;
- *td->buffer2 << "</h1>\r\n<hr />\r\n";
-
- ret = appendDataToHTTPChannel(td, td->buffer2->getBuffer(),
- td->buffer2->getLength(),
- &(td->outputData), &chain,
- td->appendOutputs, useChunks);
-
- if(ret)
- {
- td->outputData.closeFile();
- /* Return an internal server error. */
- return td->http->raiseHTTPError(500);
- }
- sentData += td->buffer2->getLength();
-
- ret = fd.findfirst(filename.c_str());
-
- if(ret == -1)
- {
- chain.clearAllFilters();
- return td->http->raiseHTTPError(404);
- }
-
- /*
- *With the current code we build the HTML TABLE to indicize the
- *files in the directory.
- */
- td->buffer2->setLength(0);
- *td->buffer2 << "<table width=\"100%\">\r\n<tr>\r\n" ;
-
- if(sortType == 'f' && !sortReverse)
- *td->buffer2 << "<th><a href=\"?sort=fI\">File</a></th>\r\n";
- else
- *td->buffer2 << "<th><a href=\"?sort=f\">File</a></th>\r\n";
-
- if(sortType == 't' && !sortReverse)
- *td->buffer2 << "<th><a href=\"?sort=tI\">Last Modified</a></th>\r\n";
- else
- *td->buffer2 << "<th><a href=\"?sort=t\">Last Modified</a></th>\r\n";
-
- if(sortType == 's' && !sortReverse)
- *td->buffer2 << "<th><a href=\"?sort=sI\">Size</a></th>\r\n</tr>\r\n";
- else
- *td->buffer2 << "<th><a href=\"?sort=s\">Size</a></th>\r\n</tr>\r\n";
-
- ret = appendDataToHTTPChannel(td, td->buffer2->getBuffer(),
- td->buffer2->getLength(),
- &(td->outputData), &chain,
- td->appendOutputs, useChunks);
-
- if(ret)
- {
- td->outputData.closeFile();
- chain.clearAllFilters();
- /* Return an internal server error. */
- return td->http->raiseHTTPError(500);
- }
-
- sentData += td->buffer2->getLength();
-
- td->buffer2->setLength(0);
-
- if(FilesUtility::getPathRecursionLevel(td->request.uri) >= 1)
- {
- string file;
- file.assign(td->request.uri);
- file.append("/../");
-
- *td->buffer2 << "<tr>\r\n<td colspan=\"2\">"
- << "<a href=\""
- << (td->request.uriEndsWithSlash ? ".." : ".")
- << "\">[ .. ]</a></td>\n"
- << "<td>[directory]</td></tr>\r\n";
-
- ret = appendDataToHTTPChannel(td, td->buffer2->getBuffer(),
- td->buffer2->getLength(),
- &(td->outputData), &chain,
- td->appendOutputs, useChunks);
- if(ret)
- {
- fd.findclose();
- td->outputData.closeFile();
- chain.clearAllFilters();
- /* Return an internal server error. */
- return td->http->raiseHTTPError(500);
- }
- sentData += td->buffer2->getLength();
- }
-
- /* Put all files in a vector. */
- do
- {
- if(fd.name[0] == '.')
- continue;
- /* Do not show the security file. */
- if(!strcmp(fd.name, "security"))
- continue;
-
- FileStruct file;
- file.name.assign(fd.name);
- file.time_write = fd.time_write;
- file.attrib = fd.attrib;
- file.size = fd.size;
- files.push_back(file);
-
- }
- while(!fd.findnext());
-
- fd.findclose();
-
- /* Sort the vector. */
- switch(sortType)
- {
- case 's':
- sort (files.begin(), files.end(), compareFileStructBySize);
- break;
- case 't':
- sort (files.begin(), files.end(), compareFileStructByTime);
- break;
- case 'f':
- sort (files.begin(), files.end(), compareFileStructByName);
- }
-
- if(sortReverse)
- reverse (files.begin(), files.end());
-
- /* Build the files table and send it. */
- for(vector<FileStruct>::iterator it = files.begin();
- it != files.end(); it++)
- {
- string formattedName;
-
- FileStruct& file = *it;
-
- td->buffer2->setLength(0);
-
- *td->buffer2 << "<tr>\r\n<td><a href=\"";
- if(!td->request.uriEndsWithSlash)
- {
- *td->buffer2 << &td->request.uri[lastSlash];
- *td->buffer2 << "/" ;
- }
- formattedName.assign(file.name);
-
- formatHtml(file.name, formattedName);
-
- *td->buffer2 << formattedName ;
- *td->buffer2 << "\">" ;
- *td->buffer2 << formattedName;
- *td->buffer2 << "</a></td>\r\n<td>";
-
- getRFC822GMTTime(file.time_write, fileTime, 32);
-
- *td->buffer2 << fileTime ;
- *td->buffer2 << "</td>\r\n<td>";
-
- if(file.attrib & FILE_ATTRIBUTE_DIRECTORY)
- {
- *td->buffer2 << "[directory]";
- }
- else
- {
- string out;
- getFormattedSize(file.size, out);
- *td->buffer2 << out;
- }
-
- *td->buffer2 << "</td>\r\n</tr>\r\n";
- ret = appendDataToHTTPChannel(td, td->buffer2->getBuffer(),
- td->buffer2->getLength(),
- &(td->outputData), &chain,
- td->appendOutputs, useChunks);
- if(ret)
- {
- td->outputData.closeFile();
- chain.clearAllFilters();
- /* Return an internal server error. */
- return td->http->raiseHTTPError(500);
- }
-
- sentData += td->buffer2->getLength();
-
- }
-
- td->buffer2->setLength(0);
- *td->buffer2 << "</table>\r\n<hr />\r\n<address>GNU MyServer "
- << versionOfSoftware;
-
- if(host && host->value->length())
- {
- ostringstream portBuff;
- size_t portSeparator = host->value->find(':');
- *td->buffer2 << " on ";
- if(portSeparator != string::npos)
- *td->buffer2 << host->value->substr(0, portSeparator).c_str() ;
- else
- *td->buffer2 << host->value->c_str() ;
-
- *td->buffer2 << " Port ";
- portBuff << td->connection->getLocalPort();
- *td->buffer2 << portBuff.str();
- }
- *td->buffer2 << "</address>\r\n</body>\r\n</html>\r\n";
- ret = appendDataToHTTPChannel(td, td->buffer2->getBuffer(),
- td->buffer2->getLength(),
- &(td->outputData), &chain,
- td->appendOutputs, useChunks);
-
- if(ret)
- {
- td->outputData.closeFile();
- /* Return an internal server error. */
- return td->http->raiseHTTPError(500);
- }
- sentData += td->buffer2->getLength();
-
- *td->buffer2 << end_str;
- /* Changes the \ character in the / character. */
- bufferloop = td->buffer2->getBuffer();
- while(*bufferloop++)
- if(*bufferloop == '\\')
- *bufferloop = '/';
-
- if(!td->appendOutputs && useChunks)
- {
- if(chain.write("0\r\n\r\n", 5, &nbw))
- return 1;
- }
-
- /* For logging activity. */
- td->sentData += sentData;
-
- chain.clearAllFilters();
- return 1;
-
-}
-
-/*!
- *Format a string to html.
- *\param name String to convert.
- *\param out HTML converted string.
- */
-void HttpDir::formatHtml(string& in, string& out)
-{
- string::size_type pos = 0;
- out.assign(in);
- /*
- *Replace characters in the ranges 32-65 91-96 123-126 160-255
- *with "&#CODE;".
- */
- for(pos = 0; out[pos] != '\0'; pos++)
- {
- if(((u_char)out[pos] >= 32 &&
- (u_char)out[pos] <= 65) ||
- ((u_char)out[pos] >= 91 &&
- (u_char)out[pos] <= 96) ||
- ((u_char)out[pos] >= 123 &&
- (u_char)out[pos] <= 126) ||
- ((u_char)out[pos] >= 160 &&
- (u_char)out[pos] < 255))
- {
- ostringstream os;
- os << "&#" << (int)((unsigned char)out[pos]) << ";";
- out.replace(pos, 1, os.str());
- pos += os.str().length() - 1;
- }
- }
-}
Deleted: trunk/myserver/src/protocol/http/http_file.cpp
===================================================================
--- trunk/myserver/src/protocol/http/http_file.cpp 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/src/protocol/http/http_file.cpp 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -1,627 +0,0 @@
-/*
-MyServer
-Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-
-#include <include/protocol/http/http.h>
-#include <include/protocol/http/http_headers.h>
-#include <include/protocol/http/http_file.h>
-#include <include/filter/gzip/gzip.h>
-#include <include/server/server.h>
-#include <include/filter/filters_chain.h>
-
-#include <sstream>
-#include <algorithm>
-using namespace std;
-
-extern "C"
-{
-#ifdef WIN32
-#include <direct.h>
-#include <errno.h>
-#endif
-
-#ifdef NOT_WIN
-#include <string.h>
-#include <errno.h>
-#ifdef SENDFILE
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/sendfile.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-#endif
-#endif
-}
-
-/*!
- *Send a file to the client using the HTTP protocol.
- *\param td The current HTTP thread context.
- *\param s A pointer to the connection.
- *\param filenamePath The path of the static file to send.
- *\param exec Not used.
- *\param onlyHeader Specify if send only the HTTP header.
- */
-int HttpFile::send(HttpThreadContext* td, ConnectionPtr s,
- const char *filenamePath, const char* /*exec*/,
- int /*execute*/, int onlyHeader)
-{
- /*
- *With this routine we send a file through the HTTP protocol.
- *Open the file and save its handle.
- */
- int ret;
-
- /*
- *Will we use GZIP compression to send data?
- */
- bool useGzip = false;
- u_long filesize = 0;
- File *file = 0;
- u_long bytesToSend;
- u_long firstByte = td->request.rangeByteBegin;
- u_long lastByte = td->request.rangeByteEnd;
- bool keepalive = false;
- bool useChunks = false;
- bool useModifiers = false;
- MemoryStream memStream(td->buffer2);
- FiltersChain chain;
- u_long nbw;
- u_long nbr;
-
- u_long dataSent = 0;
-
- try
- {
- file = Server::getInstance()->getCachedFiles()->open(filenamePath);
- if(file == 0)
- {
- return td->http->raiseHTTPError(500);
- }
- /*
- *Check how many bytes are ready to be send.
- */
- filesize = file->getFileSize();
- bytesToSend = filesize;
- if(lastByte == 0)
- {
- lastByte = bytesToSend;
- }
- else
- {
- /*
- *If the client use ranges set the right value
- *for the last byte number.
- */
- lastByte = std::min(lastByte + 1, bytesToSend);
- }
-
- /*
- * bytesToSend is the interval between the first and the last byte.
- */
- bytesToSend = lastByte - firstByte;
-
- /*
- * If fail to set the file pointer returns an internal server error.
- */
- ret = file->setFilePointer(firstByte);
- if(ret)
- {
- file->closeFile();
- delete file;
- return td->http->raiseHTTPError(500);
- }
-
-
- {
- /*
- *Use GZIP compression to send files bigger than GZIP threshold.
- */
- const char* val = s->host->getHashedData("GZIP_THRESHOLD");
- useGzip = false;
- if(val)
- {
- u_long gzipThreshold = atoi(val);
- if(bytesToSend >= gzipThreshold)
- useGzip = true;
- }
-
- }
-
- keepalive = td->request.isKeepAlive();
-
-#ifndef DO_NOT_USEGZIP
- /*
- *Be sure that the client accept GZIP compressed data.
- */
- if(useGzip)
- {
- HttpRequestHeader::Entry* e = td->request.other.get("Accept-Encoding");
- if(e)
- {
- useGzip &= (e->value->find("gzip") != string::npos);
- }
- else
- useGzip = false;
-
- }
-#else
- /*
- * If compiled without GZIP support force the server to don't use it.
- */
- useGzip = false;
-#endif
- if(td->appendOutputs)
- useGzip = false;
-
- td->buffer->setLength(0);
-
- /* If a Range was requested send 206 and not 200 for success. */
- if( td->request.rangeByteBegin || td->request.rangeByteEnd )
- {
- HttpResponseHeader::Entry *e;
- ostringstream buffer;
- td->response.httpStatus = 206;
- buffer << "bytes "<< (u_long)firstByte << "-"
- << (u_long)lastByte << "/" << (u_long)filesize ;
-
- e = td->response.other.get("Content-Range");
- if(e)
- e->value->assign(buffer.str());
- else
- {
- e = new HttpResponseHeader::Entry();
- e->name->assign("Content-Range");
- e->value->assign(buffer.str());
- td->response.other.put(*(e->name), e);
- }
-
-
- e = td->response.other.get("Transfer-Encoding");
- if(e)
- e->value->assign("chunked");
- else
- {
- e = new HttpResponseHeader::Entry();
- e->name->assign("Transfer-Encoding");
- e->value->assign("chunked");
- td->response.other.put(*(e->name), e);
- }
-
- useGzip = false;
- }
- chain.setProtocol(td->http);
- chain.setProtocolData(td);
- chain.setStream(&memStream);
- if(td->mime)
- {
- if(td->mime &&
- Server::getInstance()->getFiltersFactory()->chain(&chain,
- td->mime->filters,
- &memStream,
- &nbw))
- {
- file->closeFile();
- delete file;
- chain.clearAllFilters();
- return 0;
- }
- memStream.refresh();
-
- dataSent += nbw;
- }
-
- if(useGzip && !chain.isFilterPresent("gzip"))
- {
- Filter* gzipFilter =
- Server::getInstance()->getFiltersFactory()->getFilter("gzip");
- u_long nbw;
- if(!gzipFilter)
- {
- file->closeFile();
- delete file;
- chain.clearAllFilters();
- return 0;
- }
- if(chain.addFilter(gzipFilter, &nbw))
- {
- delete gzipFilter;
- file->closeFile();
- delete file;
- chain.clearAllFilters();
- return 0;
- }
- dataSent += nbw;
- }
-
- useModifiers = chain.hasModifiersFilters();
-
- if(keepalive && !useModifiers)
- {
- ostringstream buffer;
- buffer << (u_int)bytesToSend;
- td->response.contentLength.assign(buffer.str());
- }
-
- /* Specify the connection type. */
- if(keepalive)
- {
- td->response.connection.assign("keep-alive");
- }
- else
- {
- td->response.connection.assign("close");
- }
-
- if(useModifiers)
- {
- string s;
- HttpResponseHeader::Entry *e;
- chain.getName(s);
- e = td->response.other.get("Content-Encoding");
- if(e)
- e->value->assign(s);
- else
- {
- e = new HttpResponseHeader::Entry();
- e->name->assign("Content-Encoding");
- e->value->assign(s);
- td->response.other.put(*(e->name), e);
- }
- /* Do not use chunked transfer with old HTTP/1.0 clients. */
- if(keepalive)
- {
- HttpResponseHeader::Entry *e;
- e = td->response.other.get("Transfer-Encoding");
- if(e)
- e->value->assign("chunked");
- else
- {
- e = new HttpResponseHeader::Entry();
- e->name->assign("Transfer-Encoding");
- e->value->assign("chunked");
- td->response.other.put(*(e->name), e);
- }
-
- useChunks = true;
- }
- }
-
- HttpHeaders::buildHTTPResponseHeader(td->buffer->getBuffer(),
- &td->response);
- td->buffer->setLength((u_long)strlen(td->buffer->getBuffer()));
- if(!td->appendOutputs)
- {
- /* Send the HTTP header. */
- if(s->socket->send(td->buffer->getBuffer(),
- (u_long)td->buffer->getLength(), 0) == SOCKET_ERROR)
- {
- file->closeFile();
- delete file;
- chain.clearAllFilters();
- return 1;
- }
- }
-
- /*
- *If is requested only the header exit from the function;
- *used by the HEAD request.
- */
- if(onlyHeader)
- {
- file->closeFile();
- delete file;
- chain.clearAllFilters();
- return 0;
- }
-
-#ifdef SENDFILE
- /*
- * Check if there are all the conditions to use a direct copy from the
- * file to the socket. The sendfile syscall copy from a descriptor to
- * another directly in the kernel space without performs an extra copy
- * to an userspace buffer.
- */
- if(!useChunks && chain.isEmpty() &&
- !td->appendOutputs && (file->getHandle() != -1) &&
- !(td->http->getProtocolOptions() & PROTOCOL_USES_SSL))
- {
- off_t offset = firstByte;
- ret = sendfile(s->socket->getHandle(), file->getHandle(),
- &offset, bytesToSend);
- file->closeFile();
- delete file;
- chain.clearAllFilters();
-
- /* For logging activity. */
- td->sentData += ret;
-
- return 0;
- }
-#endif
-
- if(td->appendOutputs)
- chain.setStream(&(td->outputData));
- else
- chain.setStream(s->socket);
-
- /*
- *Flush initial data. This is data that filters could have added
- *and we have to send before the file itself, for example the gzip
- *filter add a header to file.
- */
- if(memStream.availableToRead())
- {
- ret = memStream.read(td->buffer->getBuffer(),
- td->buffer->getRealLength(),
- &nbr);
-
- if(ret)
- {
- file->closeFile();
- delete file;
- chain.clearAllFilters();
- return 0;
- }
-
- memStream.refresh();
-
- if(nbr)
- {
- if(HttpDataHandler::appendDataToHTTPChannel(td,
- td->buffer->getBuffer(),
- nbr,
- &(td->outputData),
- chain.getStream(),
- td->appendOutputs,
- useChunks))
- {
- file->closeFile();
- delete file;
- chain.clearAllFilters();
- return 1;
- dataSent += nbw;
- }
- } /* nbr. */
- } /* memStream.availableToRead(). */
-
-
- /* Flush the rest of the file. */
- for(;;)
- {
- u_long nbr;
- u_long nbw;
-
- /* Check if there are other bytes to send. */
- if(bytesToSend)
- {
- /* Read from the file the bytes to send. */
- ret = file->readFromFile(td->buffer->getBuffer(),
- std::min(static_cast<u_long>(bytesToSend),
-
static_cast<u_long>(td->buffer->getRealLength()/2)),
- &nbr);
- if(ret)
- break;
-
- if(nbr == 0)
- {
- bytesToSend = 0;
- continue;
- }
-
- bytesToSend -= nbr;
-
-
- ret = appendDataToHTTPChannel(td, td->buffer->getBuffer(),
- nbr,
- &(td->outputData),
- &chain,
- td->appendOutputs,
- useChunks,
- td->buffer->getRealLength(),
- &memStream);
- if(ret)
- break;
-
- dataSent += nbr;
- }
- else /* if(bytesToSend) */
- {
- /* If we don't use chunks we can flush directly. */
- if(!useChunks)
- {
- ret = chain.flush(&nbw);
-
- break;
- }
- else
- {
- /*
- *Replace the final stream before the flush and write to a
- *memory buffer, after all the data is flushed from the
- *chain we can replace the stream with the original one and
- *write there the HTTP data chunk.
- */
- Stream* tmpStream = chain.getStream();
-
- chain.setStream(&memStream);
-
- memStream.refresh();
-
- ret = chain.flush(&nbw);
-
- if(ret)
- break;
-
- chain.setStream(tmpStream);
-
- ret = memStream.read(td->buffer->getBuffer(),
- td->buffer->getRealLength(),
- &nbr);
- if(ret)
- break;
-
- ret = HttpDataHandler::appendDataToHTTPChannel(td,
-
td->buffer->getBuffer(),
- nbr,
- &(td->outputData),
- chain.getStream(),
- td->appendOutputs,
- useChunks);
- if(ret)
- break;
-
- ret = HttpDataHandler::appendDataToHTTPChannel(td,
- 0,
- 0,
- &(td->outputData),
- chain.getStream(),
- td->appendOutputs,
- useChunks);
-
- break;
- }
- }
-
- memStream.refresh();
-
- }/* End for loop. */
-
- file->closeFile();
- delete file;
- }
- catch(bad_alloc &ba)
- {
- file->closeFile();
- delete file;
- s->host->warningsLogRequestAccess(td->id);
- s->host->warningsLogWrite("HttpFile: Error allocating memory");
- s->host->warningsLogTerminateAccess(td->id);
- chain.clearAllFilters();
- return td->http->raiseHTTPError(500);
- }
- catch(...)
- {
- file->closeFile();
- delete file;
- s->host->warningsLogRequestAccess(td->id);
- s->host->warningsLogWrite("HttpFile: Internal error");
- s->host->warningsLogTerminateAccess(td->id);
- chain.clearAllFilters();
- return td->http->raiseHTTPError(500);
- };
-
- /* For logging activity. */
- td->sentData += dataSent;
-
- chain.clearAllFilters();
- return !ret;
-}
-
-/*!
- *Constructor for the class.
- */
-HttpFile::HttpFile()
-{
-
-}
-
-/*!
- *Destroy the object.
- */
-HttpFile::~HttpFile()
-{
-
-}
-
-/*!
- *Load the static elements.
- *\param confFile Not used.
- */
-int HttpFile::load(XmlParser* /*confFile*/)
-{
- return 0;
-}
-
-/*!
- *Unload the static elements.
- */
-int HttpFile::unLoad()
-{
- return 0;
-}
-
-/*!
- *Custom version for the appendDataToHTTPChannel function, this is
- *slower that the HttpDataHandler one but the internal buffer is
- *needed by the filters chain.
- *\param td The HTTP thread context.
- *\param buffer Data to send.
- *\param size Size of the buffer.
- *\param appendFile The file where append if in append mode.
- *\param chain Where send data if not append.
- *\param append Append to the file?
- *\param useChunks Can we use HTTP chunks to send data?
- *\param realBufferSize The real dimension of the buffer that can be
- *used by this method.
- *\param tmpStream A support on memory read/write stream used
- *internally by the function.
- */
-int HttpFile::appendDataToHTTPChannel(HttpThreadContext* td,
- char* buffer,
- u_long size,
- File* appendFile,
- FiltersChain* chain,
- bool append,
- bool useChunks,
- u_long realBufferSize,
- MemoryStream *tmpStream)
-{
- u_long nbr, nbw;
- Stream *oldStream = chain->getStream();
-
- /*
- *This function can't append directly to the chain because we can't
- *know in advance the data chunk size. Therefore we replace the
- *final stream with a memory buffer and write there the final data
- *chunk content, finally we read from it and send directly on the
- *original stream.
- */
- chain->setStream(tmpStream);
-
- if(chain->write(buffer, size, &nbw))
- return 1;
-
- if(tmpStream->read(buffer, realBufferSize, &nbr))
- return 1;
-
- chain->setStream(oldStream);
-
- /*
- *Use of chain->getStream() is needed to write directly on the
- *final stream.
- */
- return HttpDataHandler::appendDataToHTTPChannel(td,
- buffer,
- nbr,
- appendFile,
- chain->getStream(),
- append,
- useChunks);
-
-}
Modified: trunk/myserver/src/protocol/http/http_headers.cpp
===================================================================
--- trunk/myserver/src/protocol/http/http_headers.cpp 2008-09-01 19:56:39 UTC
(rev 2779)
+++ trunk/myserver/src/protocol/http/http_headers.cpp 2008-09-02 19:00:55 UTC
(rev 2780)
@@ -39,10 +39,6 @@
#endif
}
-#ifdef NOT_WIN
-#include <include/find_data/find_data.h>
-#endif
-
/*!
*Builds an HTTP header string starting from an HttpResponseHeader structure.
*\param str The buffer where write the HTTP header.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [myserver-commit] [2780] Files refactoring.,
Giuseppe Scrivano <=