[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[myserver-commit] [2874] Use the new LogManager interface in its depende
From: |
Francesco Pipita |
Subject: |
[myserver-commit] [2874] Use the new LogManager interface in its dependent classes. |
Date: |
Wed, 08 Oct 2008 22:21:12 +0000 |
Revision: 2874
http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=2874
Author: francesco_pipita
Date: 2008-10-08 22:21:10 +0000 (Wed, 08 Oct 2008)
Log Message:
-----------
Use the new LogManager interface in its dependent classes.
Modified Paths:
--------------
trunk/myserver/binaries/virtualhosts.xml.default
trunk/myserver/binaries/virtualhosts.xml.unix.default
trunk/myserver/documentation/log_management.texi
trunk/myserver/include/conf/vhost/vhost.h
trunk/myserver/include/conf/vhost/vhost_manager.h
trunk/myserver/include/filter/console.h
trunk/myserver/include/log/log_manager.h
trunk/myserver/include/log/stream/console_stream.h
trunk/myserver/include/log/stream/console_stream_creator.h
trunk/myserver/include/log/stream/file_stream.h
trunk/myserver/include/log/stream/file_stream_creator.h
trunk/myserver/include/log/stream/log_stream.h
trunk/myserver/include/log/stream/log_stream_creator.h
trunk/myserver/include/log/stream/log_stream_factory.h
trunk/myserver/include/log/stream/socket_stream.h
trunk/myserver/include/log/stream/socket_stream_creator.h
trunk/myserver/include/server/server.h
trunk/myserver/src/base/process/process_server_manager.cpp
trunk/myserver/src/conf/mime/mime_manager.cpp
trunk/myserver/src/conf/vhost/vhost.cpp
trunk/myserver/src/conf/vhost/vhost_manager.cpp
trunk/myserver/src/connections_scheduler/connections_scheduler.cpp
trunk/myserver/src/connections_scheduler/listen_threads.cpp
trunk/myserver/src/filter/console.cpp
trunk/myserver/src/http_handler/cgi/cgi.cpp
trunk/myserver/src/http_handler/fastcgi/fastcgi.cpp
trunk/myserver/src/http_handler/http_dir/http_dir.cpp
trunk/myserver/src/http_handler/http_file/http_file.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/http_handler/wincgi/wincgi.cpp
trunk/myserver/src/log/log_manager.cpp
trunk/myserver/src/log/stream/console_stream.cpp
trunk/myserver/src/log/stream/console_stream_creator.cpp
trunk/myserver/src/log/stream/file_stream.cpp
trunk/myserver/src/log/stream/file_stream_creator.cpp
trunk/myserver/src/log/stream/log_stream.cpp
trunk/myserver/src/log/stream/log_stream_creator.cpp
trunk/myserver/src/log/stream/log_stream_factory.cpp
trunk/myserver/src/log/stream/socket_stream.cpp
trunk/myserver/src/log/stream/socket_stream_creator.cpp
trunk/myserver/src/myserver.cpp
trunk/myserver/src/plugin/plugins_manager.cpp
trunk/myserver/src/protocol/control/control_protocol.cpp
trunk/myserver/src/protocol/http/http.cpp
trunk/myserver/src/server/clients_thread.cpp
trunk/myserver/src/server/server.cpp
trunk/myserver/tests/test_log_manager.cpp
trunk/myserver/tests/test_log_stream_factory.cpp
Modified: trunk/myserver/binaries/virtualhosts.xml.default
===================================================================
--- trunk/myserver/binaries/virtualhosts.xml.default 2008-10-08 19:28:07 UTC
(rev 2873)
+++ trunk/myserver/binaries/virtualhosts.xml.default 2008-10-08 22:21:10 UTC
(rev 2874)
@@ -11,8 +11,22 @@
<DOCROOT>web</DOCROOT>
<SYSFOLDER>system</SYSFOLDER>
- <ACCESSLOG>logs/MyServerHTTP.log</ACCESSLOG>
- <WARNINGLOG>logs/MyServerHTTP.err</WARNINGLOG>
+ <ACCESSLOG>
+ <STREAMS>
+ <STREAM>
+ <LOCATION>file://logs/MyServerHTTP.log</LOCATION>
+ <CYCLE>1048576</CYCLE>
+ </STREAM>
+ </STREAMS>
+ </ACCESSLOG>
+ <WARNINGLOG>
+ <STREAMS>
+ <STREAM>
+ <LOCATION>file://logs/MyServerHTTP.err</LOCATION>
+ <CYCLE>1048576</CYCLE>
+ </STREAM>
+ </STREAMS>
+ </WARNINGLOG>
</VHOST>
<VHOST>
@@ -24,7 +38,21 @@
<DOCROOT>web</DOCROOT>
<SYSFOLDER>system</SYSFOLDER>
- <ACCESSLOG>logs/MyServerFTP.log</ACCESSLOG>
- <WARNINGLOG>logs/MyServerFTP.err</WARNINGLOG>
+ <ACCESSLOG>
+ <STREAMS>
+ <STREAM>
+ <LOCATION>file://logs/MyServerFTP.log</LOCATION>
+ <CYCLE>1048576</CYCLE>
+ </STREAM>
+ </STREAMS>
+ </ACCESSLOG>
+ <WARNINGLOG>
+ <STREAMS>
+ <STREAM>
+ <LOCATION>file://logs/MyServerFTP.err</LOCATION>
+ <CYCLE>1048576</CYCLE>
+ </STREAM>
+ </STREAMS>
+ </WARNINGLOG>
</VHOST>
</VHOSTS>
Modified: trunk/myserver/binaries/virtualhosts.xml.unix.default
===================================================================
--- trunk/myserver/binaries/virtualhosts.xml.unix.default 2008-10-08
19:28:07 UTC (rev 2873)
+++ trunk/myserver/binaries/virtualhosts.xml.unix.default 2008-10-08
22:21:10 UTC (rev 2874)
@@ -11,8 +11,22 @@
<DOCROOT>/var/web/</DOCROOT>
<SYSFOLDER>/usr/local/share/myserver/system/</SYSFOLDER>
- <ACCESSLOG>/var/log/myserver/MyServerHTTP.log</ACCESSLOG>
- <WARNINGLOG>/var/log/myserver/MyServerHTTP.err</WARNINGLOG>
+ <ACCESSLOG>
+ <STREAMS>
+ <STREAM>
+
<LOCATION>file:///var/log/myserver/MyServerHTTP.log</LOCATION>
+ <CYCLE>1048576</CYCLE>
+ </STREAM>
+ </STREAMS>
+ </ACCESSLOG>
+ <WARNINGLOG>
+ <STREAMS>
+ <STREAM>
+
<LOCATION>file:///var/log/myserver/MyServerHTTP.err</LOCATION>
+ <CYCLE>1048576</CYCLE>
+ </STREAM>
+ </STREAMS>
+ </WARNINGLOG>
</VHOST>
<VHOST>
@@ -24,7 +38,21 @@
<DOCROOT>/var/web/</DOCROOT>
<SYSFOLDER>/usr/local/share/myserver/system/</SYSFOLDER>
- <ACCESSLOG>/var/log/myserver/MyServerFTP.log</ACCESSLOG>
- <WARNINGLOG>/var/log/myserver/MyServerFTP.err</WARNINGLOG>
+ <ACCESSLOG>
+ <STREAMS>
+ <STREAM>
+
<LOCATION>file:///var/log/myserver/MyServerFTP.log</LOCATION>
+ <CYCLE>1048576</CYCLE>
+ </STREAM>
+ </STREAMS>
+ </ACCESSLOG>
+ <WARNINGLOG>
+ <STREAMS>
+ <STREAM>
+
<LOCATION>file:///var/log/myserver/MyServerFTP.err</LOCATION>
+ <CYCLE>1048576</CYCLE>
+ </STREAM>
+ </STREAMS>
+ </WARNINGLOG>
</VHOST>
</VHOSTS>
Modified: trunk/myserver/documentation/log_management.texi
===================================================================
--- trunk/myserver/documentation/log_management.texi 2008-10-08 19:28:07 UTC
(rev 2873)
+++ trunk/myserver/documentation/log_management.texi 2008-10-08 22:21:10 UTC
(rev 2874)
@@ -2,114 +2,103 @@
@section Overview of the log management features
The MyServer's log management system was designed to support logging
-over different targets. By default, log messages can be sent to a file,
-to a socket and of course to the console. The main class which achieves
-logging tasks is still the @code{LogManager} class. One single instance
-of it can now handle multiple targets. These targets are called
address@hidden objects. In addition, it is possible to provide a list
-of filters (e.g. the Gzip filter) to each @code{LogStream} object. This
-offers interesting possibilities, like logging over a TCP Socket while
-taking advantage of the Gzip compression. The new @code{LogManager} also
-ensures that all the operations that modify its internal data
-structures, through its interface, are atomics.
+over different targets. At the moment, these targets are made out of
+files, sockets and, of course, consoles. Each target, must be referred
+through its @b{location string}. In addition, it is possible to provide
+a list of filters (e.g. the Gzip filter) to improve the logging
+capabilities.
address@hidden Use of the new LogManager interface
-This section introduces the use of the new @code{LogManager}'s
-interface.
address@hidden Use of the log manager
+This section will introduce you to the use of the log management
+features.
address@hidden Construction
-The @code{LogManager} constructor, requires an instance of
address@hidden, an instance of @code{LogStreamFactory} and a
-logging level, choosen between @code{INFO, WARNING, ERROR}. The third
-parameter is optional.
address@hidden Location strings
+A location string must be provided in the form
address@hidden://resource}, where @code{protocol} can ben choosen
+between :
address@hidden
address@hidden @code{console}
address@hidden @code{file}
address@hidden @code{socket}
address@hidden enumerate
+while @code{resource} must be a valid filename or URL according to its
address@hidden The @code{console} protocol, can take as its
address@hidden argument, either @code{stdout} or @code{stderr}.
+
address@hidden Location string examples
address@hidden
address@hidden Send log messages to a host whose ip address is 192.168.1.18, on
+port 12345 :
@example
-LogManager (FiltersFactory* filtersFactory,
- LogStreamFactory* logStreamFactory,
- LoggingLevel level = WARNING);
+socket://192.168.1.18:12345
@end example
-
-
address@hidden Adding a new LogStream target
-The adding of a new @code{LogStream} target can be done calling the
address@hidden method over an instance of the
address@hidden Below, we can look at the method signature :
address@hidden Send log messages to the file /var/log/myserver/MyServerHTTP.log
:
@example
-int addLogStream (string location,
- list<string>& filters,
- u_long cycleLog);
+file:///var/log/myserver/MyServerHTTP.log
@end example
-The @code{location} string holds the location where the @code{LogStream}
-will point to as well as the protocol it will use. That string must
-follow a special syntax, that will be covered in next section. The
address@hidden parameter holds a list of filter names that will be added
-to the @code{LogStream}. Finally, the @code{cycleLog} parameter holds
-the max size, in bytes, that the new @code{LogStream} can reach. Over
-that limit, the @code{LogStream} will be cycled, that is, its content
-will be saved somewhere else. The current @code{LogStream} will be
-emptied and the location name of its saved content, will be available
-looking at the latest element of a FIFO queue returned by the
address@hidden method. The @code{addLogStream} method returns a
-zero value if the new @code{LogStream} was successful added, a non-zero
-value otherwise, according to the MyServer standard.
-
address@hidden Location strings
-A location string must be provided in the form
address@hidden://path/to/resource}'. The address@hidden://}' part is
-used by the @code{LogStreamFactory} to fetch the proper constructor for
-the new object that it will create. The address@hidden/to/resource}' part,
-instead, is used within the @code{LogStreamCreator}. The
address@hidden creation process, must ensure, through checks at
-increasing depth levels, that only valid @code{LogStream} objects can
-be returned. For example, syntactically a location string like
address@hidden://foo_host:-1}' is correct, but of course, the
address@hidden/to/resource}' part doesn't represent any valid host:port
-pair for a socket. So giving a such location string, the
address@hidden method, must fail.
-
address@hidden Removing an existing LogStream
-The interface provides also a method that can detach a @code{LogStream}
-from the @code{LogManager}. Here is the method signature :
+Note the extra '/' needed to refer an absolute path.
address@hidden Send log messages to the standard error
@example
-int removeLogStream (string location);
+console://stderr
@end example
-It will remove the @code{LogStream} that points to @code{location}. If
-the provided location doesn't belong to the @code{LogManager}, the
-method doesn't nothing and it simply returns a non-zero value.
address@hidden enumerate
address@hidden Adding new LogStream classes
-To add new targets which can be used within the @code{LogManager}, you
-have to subclass the @code{LogStream} class. Then, if needed, override
-the following virtual methods :
address@hidden Setting the MyServer's main log
+You can set the MyServer's main log location through the switch
@example
-virtual u_long streamSize ();
-virtual int streamCycle ();
+--loglocation=protocol://resource
@end example
-The first one should return the size of the @code{Stream} owned by the
address@hidden while the second should manage its cycling process. The
-return value for the latter method must conform with the MyServer
-standard. The next step is to subclass @code{LogStreamCreator},
-overriding the @code{create} abstract method. Finally, you have to add
-the new @code{LogStreamCreator} to the @code{LogStreamFactory}, merely
-adding a line to its constructor, something that looks like :
+where the @code{--loglocation} argument is a valid location string.
+
address@hidden Setting the logging resources for virtual hosts
+Each virtual host needs two main log targets, one for the access
+messages and the other one for the error messages, whose entries in the
+configuration file, are respectively @code{ACCESSLOG} and
address@hidden Each of these targets, can in turn write its
+messages over different streams. To tell MyServer about all that, you
+can edit the @file{virtualhosts.xml} file, and apply the informations
+found in this section, to each @code{VHOST} entry of that file. As we
+can see in the following example, the @code{ACCESSLOG} root entry for
+the accesses log configuration, contains some @code{STREAMS}, and each
address@hidden is made out of a @code{LOCATION}, a @code{CYCLE} and some
address@hidden
@example
-logStreamCreators["foo://"] = new FooStreamCreator ();
+<ACCESSLOG type="combined">
+ <STREAMS>
+ <STREAM>
+ <LOCATION>file://logs/MyServerHTTP.log</LOCATION>
+ <CYCLE>1048576</CYCLE>
+ <FILTERS>
+ <FILTER>gzip</FILTER>
+ </FILTERS>
+ </STREAM>
+ <STREAM>
+ <LOCATION>console://stderr</LOCATION>
+ </STREAM>
+ </STREAMS>
+</ACCESSLOG>
@end example
-
address@hidden Writing log messages on the LogStream objects
-To log messages, simply call the method @code{log} on a
address@hidden object. That method takes three parameters, but only
-the first one is needed.
+Above we have two streams attached to the @code{ACCESSLOG} entry. The
+first one, is a file. This file will grow up to 1048576 bytes, over that
+limit it will be cycled. Also, this target will take advantage of the
+gzip compression, since it will write to the file through the gzip
+filter. The second one is the standard error stream over the console.
+The next example, shows instead the @code{WARNINGLOG} entry. In that
+example, we still have two streams where warning messages will be
+sent. The first one is a socket, while the second one is a file that
+will grow with no limit over its size. No filters will be applied to
+that stream.
@example
-int log (string message,
- LoggingLevel level = WARNING,
- string location = "all");
+<WARNINGLOG>
+ <STREAMS>
+ <STREAM>
+ <LOCATION>socket://192.168.1.13:8080</LOCATION>
+ </STREAM>
+ <STREAM>
+ <LOCATION>file://MyServerHTTP.err</LOCATION>
+ </STREAM>
+ </STREAMS>
+</WARNINGLOG>
@end example
-The first parameter represent a message to output on the log. The
address@hidden parameter represent the @code{LoggingLevel} of the incoming
-message. If it is lesser than the @code{LogManager}'s logging level, the
address@hidden discards the message. The @code{location} parameter
-tells the @code{LogManager} to output the message only to the specified
-location. By default, if no @code{location} is provided, the
address@hidden will log the message on all its
address@hidden objects. If a non-valid or non-existent location is
-provided, the @code{LogManager} simply discards the message.
+It is important to notice that no duplicate location strings are
+admitted. If any, only the first one will be added.
Modified: trunk/myserver/include/conf/vhost/vhost.h
===================================================================
--- trunk/myserver/include/conf/vhost/vhost.h 2008-10-08 19:28:07 UTC (rev
2873)
+++ trunk/myserver/include/conf/vhost/vhost.h 2008-10-08 22:21:10 UTC (rev
2874)
@@ -1,24 +1,27 @@
/* -*- mode: c++ -*- */
/*
-MyServer
-Copyright (C) 2002, 2003, 2004, 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.
+ MyServer
+ Copyright (C) 2002, 2003, 2004, 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.
+ 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/>.
+ 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 VHOST_H
#define VHOST_H
+#include <list>
+#include <string>
+
#include "stdafx.h"
#include <include/base/xml/xml_parser.h>
#include <include/base/file/file.h>
@@ -31,18 +34,15 @@
#include <include/base/sync/mutex.h>
#include <include/base/ssl/ssl.h>
#include <include/connections_scheduler/listen_threads.h>
-#include <string>
-#include <list>
-
using namespace std;
typedef int (*NULL_REFERENCECB)(class Vhost*);
class VhostProtocolData
{
public:
- VhostProtocolData(){}
- virtual ~VhostProtocolData(){}
+ VhostProtocolData(){}
+ virtual ~VhostProtocolData(){}
};
class Vhost
@@ -50,143 +50,109 @@
public:
friend class VhostManager;
- struct StringRegex
- {
- string name;
+ struct StringRegex
+ {
+ string name;
Regex regex;
StringRegex() : regex()
- {}
+ {}
~StringRegex()
- {}
- };
+ {}
+ };
/*! Get the host name. */
const char* getName()
- {return name.c_str();}
+ {return name.c_str();}
/*! Set the host name. */
void setName(const char* c)
- {name.assign(c);}
-
- /*! Get the accesses log file name. */
- const char* getAccessesLogFileName()
- {return accessesLogFileName.c_str();}
-
- /*! Set the accesses log file name. */
- void setAccessesLogFileName(const char* n)
- {accessesLogFileName.assign(n);}
-
- /*! Get the warnings log file name. */
- const char* getWarningsLogFileName()
- {return warningsLogFileName.c_str();}
-
- /*! Set the warnings log file name. */
- void setWarningsLogFileName(const char* n)
- {warningsLogFileName.assign(n);}
-
+ {name.assign(c);}
+
/*! Get the system root. */
const string& getSystemRoot()
- {return systemRoot;}
+ {return systemRoot;}
/*! Set the system root. */
void setSystemRoot(const char* n)
- {systemRoot.assign(n);}
+ {systemRoot.assign(n);}
/*! Get the document root. */
const string& getDocumentRoot()
- {return documentRoot;}
+ {return documentRoot;}
/*! Set the document root. */
void setDocumentRoot(const char* n)
- {documentRoot.assign(n);}
+ {documentRoot.assign(n);}
- /*! Get the access log file options. */
- const char* getAccessLogOpt()
- {return accessLogOpt.c_str();}
-
- /*! Get the warnings log file options. */
- const char* getWarningLogOpt()
- {return warningLogOpt.c_str(); }
-
- /*! Set the access log file options. */
- void setAccessLogOpt(const char* c)
- {accessLogOpt.assign(c);}
-
- /*! Set the warnings log file options. */
- void setWarningLogOpt(const char* c)
- {warningLogOpt.assign(c); }
-
/*! Get a pointer to the vhost SSL context. */
SslContext *getVhostSSLContext()
- {return &sslContext;}
+ {return &sslContext;}
- /*! Initialize SSL things. */
- int initializeSSL();
+ /*! Initialize SSL things. */
+ int initializeSSL();
- /*! Clear SSL things. */
- int freeSSL();
+ /*! Clear SSL things. */
+ int freeSSL();
- /*! Clear the data dictionary. */
- int freeHashedData();
+ /*! Clear the data dictionary. */
+ int freeHashedData();
- /*! Generate the RSA key for the SSL context. */
- void generateRsaKey();
+ /*! Generate the RSA key for the SSL context. */
+ void generateRsaKey();
- SSL_CTX* getSSLContext();
+ SSL_CTX* getSSLContext();
/*! Get the list of hosts allowed.*/
- list<StringRegex*>* getHostList()
- {return &hostList;}
+ list<StringRegex*>* getHostList()
+ {return &hostList;}
- /*! List of IPs allowed by the vhost. */
- list<StringRegex*>* getIpList()
- {return &ipList;}
+ /*! List of IPs allowed by the vhost. */
+ list<StringRegex*>* getIpList()
+ {return &ipList;}
/*! Return the port used by the host. */
- u_short getPort()
- {return port;}
+ u_short getPort()
+ {return port;}
/*! Set the port used by the host. */
- void setPort(u_short p)
- {port = p;}
+ void setPort(u_short p)
+ {port = p;}
/*! Get the protocol name for the virtual host. */
- const char* getProtocolName()
- {return protocolName.c_str();}
+ const char* getProtocolName()
+ {return protocolName.c_str();}
/*! Set the protocol name for the virtual host. */
- void setProtocolName(const char *name)
- {protocolName.assign(name);}
+ void setProtocolName(const char *name)
+ {protocolName.assign(name);}
/*! Get the throttling rate for the virtual host. */
u_long getThrottlingRate()
- {return throttlingRate;}
+ {return throttlingRate;}
/*! Set the throttling rate for the virtual host. */
void setThrottlingRate(u_long tr)
- {throttlingRate = tr;}
+ {throttlingRate = tr;}
- Vhost();
- ~Vhost();
+ Vhost(LogManager* lm);
+ ~Vhost();
const char* getHashedData(const char* name);
- void addIP(const char *, int);
- void addHost(const char *, int);
- void removeIP(const char *);
- void removeHost(const char *);
- int areAllHostAllowed();
- int areAllIPAllowed();
+ void addIP(const char *, int);
+ void addHost(const char *, int);
+ void removeIP(const char *);
+ void removeHost(const char *);
+ int areAllHostAllowed();
+ int areAllIPAllowed();
void addRef();
void removeRef();
int getRef();
void setRef(int);
- void clearIPList();
- void clearHostList();
- int isHostAllowed(const char*);
- int isIPAllowed(const char*);
- void setMaxLogSize(int);
- int getMaxLogSize();
+ void clearIPList();
+ void clearHostList();
+ int isHostAllowed(const char*);
+ int isIPAllowed(const char*);
int isMIME();
int getDefaultPriority(){return defaultPriority;}
void setDefaultPriority(int priority){defaultPriority = priority;}
@@ -195,34 +161,44 @@
MimeManager* getMIME();
- int openLogFiles(u_long maxlogSize = 0);
+ /*!
+ * \return 0 if the LogManager contains at least one valid entry where
+ * this Vhost can output both its warning and access messages.
+ */
+ int openLogFiles ();
- LogManager* getWarningsLog();
- LogManager* getAccessesLog();
+ int openAccessLog (string, list<string>&, u_long);
+ int openWarningLog (string, list<string>&, u_long);
- u_long accessesLogRequestAccess(int id);
- u_long warningsLogRequestAccess(int id);
- u_long accessesLogTerminateAccess(int id);
- u_long warningsLogTerminateAccess(int id);
+ /*! Set the access log options. */
+ void setAccessLogOpt (const char* c) { accessLogOpt.assign (c); }
+
+ /*! Set the warnings log options. */
+ void setWarningLogOpt (const char* c) { warningLogOpt.assign (c); }
- int accessesLogWrite(const char*);
- File* getAccessesLogFile();
+ /*! Get the access log options. */
+ const char* getAccessLogOpt () { return accessLogOpt.c_str (); }
- int warningsLogWrite(const char*);
- File* getWarningsLogFile();
+ /*! Get the warnings log options. */
+ const char* getWarningLogOpt () { return warningLogOpt.c_str (); }
- /*! Get the protocol data. */
- VhostProtocolData* getProtocolData(){return protocolData;}
+ /*! Write a message on the accesses log. */
+ int accessesLogWrite (const char*);
+
+ /*! Write a message on the warnings log. */
+ int warningsLogWrite (const char*);
- /*! Set the protocol data. */
- void setProtocolData(VhostProtocolData* data){protocolData = data;}
+ /*! Get the protocol data. */
+ VhostProtocolData* getProtocolData(){return protocolData;}
+
+ /*! Set the protocol data. */
+ void setProtocolData(VhostProtocolData* data){protocolData = data;}
private:
- VhostProtocolData* protocolData;
+ VhostProtocolData* protocolData;
HashMap<string, string*> hashedData;
NULL_REFERENCECB nullReferenceCb;
Mutex refMutex;
- LogManager *warningsLogFile;
- LogManager *accessesLogFile;
+ LogManager* logManager;
MimeManager mimeManager;
@@ -232,43 +208,36 @@
/*! How many connections are using this virtual host? */
int refCount;
- /*! SSL context. */
- SslContext sslContext;
+ /*! SSL context. */
+ SslContext sslContext;
- /*! List of hosts allowed by the vhost. */
- list<StringRegex*> hostList;
+ /*! List of hosts allowed by the vhost. */
+ list<StringRegex*> hostList;
- /*! List of IPs allowed by the vhost. */
- list<StringRegex*> ipList;
+ /*! List of IPs allowed by the vhost. */
+ list<StringRegex*> ipList;
- /*! TCP port used to listen on. */
- u_short port;
+ /*! TCP port used to listen on. */
+ u_short port;
/*! Throttling rate to use with the virtual host. */
- u_long throttlingRate;
+ u_long throttlingRate;
- /*! Protocol used by the vhost. */
- string protocolName;
+ /*! Protocol used by the vhost. */
+ string protocolName;
- /*! Additional data for log files. Defined in configuration files. */
- string accessLogOpt;
- string warningLogOpt;
+ /*! Path to the document root. */
+ string documentRoot;
- /*! Path to the document root. */
- string documentRoot;
+ /*! Path to the system root. */
+ string systemRoot;
- /*! Path to the system root. */
- string systemRoot;
-
- /*! Path to the accesses log file. */
- string accessesLogFileName;
-
- /*! Path to the warnings log file. */
- string warningsLogFileName;
-
- /*! Description or name of the virtual host. */
- string name;
+ /*! Description or name of the virtual host. */
+ string name;
+
+ /*! Additional data for logs. Defined in configuration files. */
+ string accessLogOpt;
+ string warningLogOpt;
};
-
#endif
Modified: trunk/myserver/include/conf/vhost/vhost_manager.h
===================================================================
--- trunk/myserver/include/conf/vhost/vhost_manager.h 2008-10-08 19:28:07 UTC
(rev 2873)
+++ trunk/myserver/include/conf/vhost/vhost_manager.h 2008-10-08 22:21:10 UTC
(rev 2874)
@@ -1,19 +1,19 @@
/* -*- mode: c++ -*- */
/*
-MyServer
-Copyright (C) 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.
+ MyServer
+ Copyright (C) 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.
+ 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/>.
+ 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 VHOST_MANAGER_H
@@ -21,57 +21,60 @@
#include "stdafx.h"
#include <include/conf/vhost/vhost.h>
+#include <include/log/log_manager.h>
-
class VhostSource
{
public:
VhostSource();
~VhostSource();
int load();
- int save();
+ int save();
int free();
Vhost* getVHost(const char*, const char*, u_short);
- Vhost* getVHostByNumber(int n);
- int addVHost(Vhost*);
+ Vhost* getVHostByNumber(int n);
+ int addVHost(Vhost*);
private:
- list<Vhost*> *hostList;
+ list<Vhost*> *hostList;
};
class VhostManager
{
public:
void setExternalSource(VhostSource* extSource);
- VhostManager(ListenThreads* lt);
- ~VhostManager();
- int getHostsNumber();
- Vhost* getVHostByNumber(int n);
- void clean();
- int removeVHost(int n);
- int switchVhosts(int n1,int n2);
- list<Vhost*>* getVHostList();
+ VhostManager(ListenThreads* lt, LogManager* lm);
+ ~VhostManager();
+ int getHostsNumber();
+ Vhost* getVHostByNumber(int n);
+ void clean();
+ int removeVHost(int n);
+ int switchVhosts(int n1,int n2);
+ list<Vhost*>* getVHostList();
- /*! Get a pointer to a vhost. */
- Vhost* getVHost(const char*,const char*,u_short);
+ /*! Get a pointer to a vhost. */
+ Vhost* getVHost(const char*,const char*,u_short);
- /*! Add an element to the vhost list. */
- int addVHost(Vhost*);
+ /*! Add an element to the vhost list. */
+ int addVHost(Vhost*);
- /*! Load the virtual hosts list from a xml configuration file. */
- int loadXMLConfigurationFile(const char *,int maxlogSize = 0);
+ /*! Load the virtual hosts list from a xml configuration file. */
+ int loadXMLConfigurationFile(const char *);
- /*! Save the virtual hosts list to a xml configuration file. */
- int saveXMLConfigurationFile(const char *);
+ /*! Save the virtual hosts list to a xml configuration file. */
+ int saveXMLConfigurationFile(const char *);
- /*! Set the right owner for the log files. */
- void changeFilesOwner();
+ /*! Set the right owner for the log locations. */
+ void changeLocationsOwner ();
private:
- ListenThreads* listenThreads;
+ void loadXMLlogData (string, Vhost*, xmlNode*);
+ string saveXMLlogData (string, Vhost*);
+ ListenThreads* listenThreads;
Mutex mutex;
- VhostSource* extSource;
+ VhostSource* extSource;
- /*! List of virtual hosts. */
- list<Vhost*> hostList;
+ /*! List of virtual hosts. */
+ list<Vhost*> hostList;
+ LogManager* logManager;
};
Modified: trunk/myserver/include/filter/console.h
===================================================================
--- trunk/myserver/include/filter/console.h 2008-10-08 19:28:07 UTC (rev
2873)
+++ trunk/myserver/include/filter/console.h 2008-10-08 22:21:10 UTC (rev
2874)
@@ -1,18 +1,19 @@
+/* -*- mode: c++ -*- */
/*
-MyServer
-Copyright (C) 2006, 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.
+ MyServer
+ Copyright (C) 2006, 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.
+ 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/>.
+ 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 CONSOLE_H
@@ -26,12 +27,17 @@
class Console : public Stream
{
- public:
+public:
Console();
virtual ~Console();
virtual int flush (u_long* nbw);
virtual int read (char* buffer, u_long len, u_long* nbr);
virtual int write (const char* buffer, u_long len, u_long* nbw);
+ virtual int enterErrorMode ();
+ virtual int exitErrorMode ();
+ virtual int openConsole (string fd);
+protected:
+ ostream* fd;
};
#endif
Modified: trunk/myserver/include/log/log_manager.h
===================================================================
--- trunk/myserver/include/log/log_manager.h 2008-10-08 19:28:07 UTC (rev
2873)
+++ trunk/myserver/include/log/log_manager.h 2008-10-08 22:21:10 UTC (rev
2874)
@@ -1,19 +1,19 @@
/* -*- mode: c++ -*- */
/*
-MyServer
-Copyright (C) 2006, 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.
+ MyServer
+ Copyright (C) 2006, 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.
+ 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/>.
+ 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 LOG_MANAGER_H
@@ -26,14 +26,15 @@
#include <include/filter/filters_factory.h>
#include <include/log/stream/log_stream.h>
#include <include/log/stream/log_stream_factory.h>
-#include <include/filter/gzip/gzip.h>
using namespace std;
+#ifdef WIN32
+#define NL "\r\n"
+#else
+#define NL "\n"
+#endif
-/*!
- * Defines different types of logging level.
- */
enum LoggingLevel
{
INFO,
@@ -41,208 +42,63 @@
ERROR
};
-
class LogManager
{
public:
-
-
- /*!
- * Default constructor. It is only used to support the old
- * interface.
- */
- LogManager ();
-
-
- LogManager (FiltersFactory* filtersFactory,
- LogStreamFactory* logStreamFactory,
- LoggingLevel level = WARNING);
-
-
- /*!
- * Deallocates all LogStream owned by the LogManager and
- * the objects (like the Mutex) allocated by the LogManager.
- * Other objects, like the FiltersFactory and the
- * LogStreamFactory should be destroied from the outside.
- */
+ LogManager (FiltersFactory* ff, LoggingLevel level = WARNING);
~LogManager ();
-
-
- /*!
- * Add a new LogStream to the LogManager. Prevents duplicate
- * LogStream being added.
- * \param location The location where the new LogStream will point.
- * \param filters A list of filters used within the new LogStream.
- * \param cycleLog A non-zero value establishes the threshold for
- * the LogStream's growth before cycling it.
- * \return 0 on success.
- */
- int addLogStream (string location,
- list<string>& filters,
- u_long cycleLog);
-
-
- /*!
- * Remove the LogStream that point to location if it exists.
- * \param location The location where the LogStream which has to
- * be removed points to.
- * \return 0 on success.
- */
- int removeLogStream (string location);
-
-
- LogStream* getLogStream (string location);
-
-
- /*!
- * Write `message' to the LogStream that points to `location'. If
- * no location is provided, it writes the message on all LogStreams
- * owned by this LogManager.
- * \param message The message string to write.
- * \param level The message logging level. If it is lower than the
- * LogManager's logging level, the LogManager discards it.
- * \param location The location where `message' will be written.
- * \return 0 on success.
- */
- int log (string message,
- LoggingLevel level = WARNING,
- string location = "all");
-
-
- /*!
- * Close the LogStream that points to `location'. If no location
- * is provided, it closes all LogStreams owned by this LogManager.
- * \return 0 on success.
- */
- int close (string location = "all");
-
-
- /*!
- * \return The cycleLog value for the LogStream that points to
- * location.
- */
- u_long getCycleLog (string location);
-
-
- /*!
- * Set the cycleLog field for the LogStream that points to `location'.
- * If no location is provided, it will set the cycleLog to the same value
- * for all LogStreams.
- * \param cycleLog The new cycleLog value.
- * \param location The LogStream whose cycleLog will be changed.
- */
- void setCycleLog (u_long cycleLog,
- string location);
-
-
- /*!
- * Set the default logging level.
- * \param level The new logging level value.
- * \return The old logging level.
- */
- LoggingLevel setLoggingLevel (LoggingLevel level);
-
-
- LoggingLevel getLoggingLevel ();
-
-
- void setLogStreamFactory (LogStreamFactory* logStreamFactory);
-
-
- LogStreamFactory* getLogStreamFactory ();
-
-
- void setFiltersFactory (FiltersFactory* filtersFactory);
-
-
+ int add (void* owner, string type, string location,
+ list<string>& filters, u_long cycle);
+ int remove (void* owner);
+ int log (void* owner, string message, bool appendNL = false,
+ LoggingLevel level = WARNING);
+ int log (void* owner, string type, string message, bool appendNL = false,
+ LoggingLevel level = WARNING);
+ int log (void* owner, string type, string location, string message,
+ bool appendNL = false, LoggingLevel level = WARNING);
+ int close (void* owner);
+ int close (void* owner, string type);
+ int close (void* owner, string type, string location);
+ int chown (void* owner, int uid, int gid);
+ int chown (void* owner, string type, int uid, int gid);
+ int chown (void* owner, string type, string location, int uid, int gid);
+ int get (void* owner, list<string>* l);
+ int get (void* owner, string type, list<string>* l);
+ int get (void* owner, string type, string location, LogStream** ls);
+ int setCycle (void* owner, u_long cycle);
+ int setCycle (void* owner, string type, u_long cycle);
+ int setCycle (void* owner, string type, string location, u_long cycle);
+ int getCycle (string location, u_long* cycle);
+ int getFilters (string location, list<string>* l);
+ LoggingLevel setLevel (LoggingLevel level);
+ LoggingLevel getLevel ();
+ void setFiltersFactory (FiltersFactory* ff);
FiltersFactory* getFiltersFactory ();
-
-
- int size ();
-
-
bool empty ();
-
-
bool contains (string location);
-
-
- /*!
- * Delete all LogStream objects owned by this LogManager.
- */
- void clear ();
-
-
- /*!
- * Deprecated methods and fields.
- */
- int getLogSize ();
- int storeFile ();
- int load (char const*);
- void setGzip (int);
- int write (string message, int len = 0);
- int writeln (string message);
- File* getFile ();
- u_long setMaxSize (u_long);
- u_long getMaxSize ();
- int getType ();
- int getGzip ();
- void setType (int);
- int preparePrintError ();
- int endPrintError ();
- int requestAccess ();
- int terminateAccess ();
- void setCycleLog (u_long);
- int const static TYPE_CONSOLE;
- int const static TYPE_FILE;
- int type;
- int gzipLog;
- int cycleLog;
- u_long maxSize;
+ bool contains (void* owner);
+ bool contains (void* owner, string type);
+ bool contains (void* owner, string type, string location);
+ int count (void* owner);
+ int count (void* owner, string type);
+ int count (void* owner, string type, string location);
+ int clear ();
protected:
-
-
- /*!
- * Send events to LogStreams.
- * \param evt The event that should be notified to LogStreams.
- * \param message The message to deliver.
- * \param reply The receiver will put its data here.
- * \return 0 on success.
- */
- int notifyLogStreams (LogStreamEvent evt,
- void* message = 0,
- void* reply = 0);
+ int notify (void* owner, string type, string location, LogStreamEvent evt,
+ void* msg = 0, void* reply = 0);
+ int notify (void* owner, string type, LogStreamEvent evt, void* msg = 0,
+ void* reply = 0);
+ int notify (void* owner, LogStreamEvent evt, void* msg = 0, void* reply = 0);
+ int add (void* owner);
+ int add (void* owner, string type);
+ int add (void* owner, string type, string location, LogStream* ls);
private:
-
-
- /*!
- * Hold the default logging level for the LogManager.
- */
LoggingLevel level;
-
-
- /*!
- * Ensure atomic operations to prevent interleaving.
- */
Mutex* mutex;
-
-
- /*!
- * The LogStream creator.
- */
- LogStreamFactory* logStreamFactory;
-
-
- /*!
- * The Filter creator.
- */
- FiltersFactory* filtersFactory;
-
-
- /*!
- * Hold all LogStream owned by this LogManager.
- */
+ LogStreamFactory* lsf;
+ FiltersFactory* ff;
map<string, LogStream*> logStreams;
+ map<void*, map<string, map<string, LogStream*> > > owners;
};
#endif
Modified: trunk/myserver/include/log/stream/console_stream.h
===================================================================
--- trunk/myserver/include/log/stream/console_stream.h 2008-10-08 19:28:07 UTC
(rev 2873)
+++ trunk/myserver/include/log/stream/console_stream.h 2008-10-08 22:21:10 UTC
(rev 2874)
@@ -1,19 +1,19 @@
/* -*- mode: c++ -*- */
/*
-MyServer
-Copyright (C) 2006, 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.
+ MyServer
+ Copyright (C) 2006, 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.
+ 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/>.
+ 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 CONSOLE_STREAM_H
@@ -27,11 +27,10 @@
class ConsoleStream : public LogStream
{
- public:
- ConsoleStream (FiltersFactory* filtersFactory,
- u_long cycleLog,
- Stream* outStream,
- FiltersChain* filtersChain);
+public:
+ ConsoleStream (FiltersFactory*, u_long, Stream*, FiltersChain*);
+ virtual int enterErrorMode ();
+ virtual int exitErrorMode ();
};
#endif
Modified: trunk/myserver/include/log/stream/console_stream_creator.h
===================================================================
--- trunk/myserver/include/log/stream/console_stream_creator.h 2008-10-08
19:28:07 UTC (rev 2873)
+++ trunk/myserver/include/log/stream/console_stream_creator.h 2008-10-08
22:21:10 UTC (rev 2874)
@@ -1,19 +1,19 @@
/* -*- mode: c++ -*- */
/*
-MyServer
-Copyright (C) 2006, 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.
+ MyServer
+ Copyright (C) 2006, 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.
+ 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/>.
+ 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 CONSOLE_STREAM_CREATOR_H
@@ -24,11 +24,8 @@
class ConsoleStreamCreator : public LogStreamCreator
{
- public:
- virtual LogStream* create (FiltersFactory* filtersFactory,
- string location,
- list<string>& filters,
- u_long cycleLog);
+public:
+ virtual LogStream* create (FiltersFactory*, string, list<string>&, u_long);
};
#endif
Modified: trunk/myserver/include/log/stream/file_stream.h
===================================================================
--- trunk/myserver/include/log/stream/file_stream.h 2008-10-08 19:28:07 UTC
(rev 2873)
+++ trunk/myserver/include/log/stream/file_stream.h 2008-10-08 22:21:10 UTC
(rev 2874)
@@ -1,19 +1,19 @@
/* -*- mode: c++ -*- */
/*
-MyServer
-Copyright (C) 2006, 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.
+ MyServer
+ Copyright (C) 2006, 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.
+ 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/>.
+ 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 FILE_STREAM_H
@@ -31,30 +31,13 @@
class FileStream : public LogStream
{
- public:
-
-
- FileStream (FiltersFactory* filtersFactory,
- u_long cycleLog,
- Stream* outStream,
- FiltersChain* filtersChain);
-
-
- /*!
- * The default file mask used to create a log file.
- */
- int const static defaultFileMask;
-
-
- virtual u_long streamSize ();
-
-
+public:
+ FileStream (FiltersFactory*, u_long, Stream*, FiltersChain*);
string makeNewFileName (string oldFileName);
-
-
- protected:
-
-
+ virtual u_long streamSize ();
+ virtual int chown (int uid, int gid);
+ int const static defaultFileMask;
+protected:
virtual int streamCycle ();
};
Modified: trunk/myserver/include/log/stream/file_stream_creator.h
===================================================================
--- trunk/myserver/include/log/stream/file_stream_creator.h 2008-10-08
19:28:07 UTC (rev 2873)
+++ trunk/myserver/include/log/stream/file_stream_creator.h 2008-10-08
22:21:10 UTC (rev 2874)
@@ -1,19 +1,19 @@
/* -*- mode: c++ -*- */
/*
-MyServer
-Copyright (C) 2006, 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.
+ MyServer
+ Copyright (C) 2006, 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.
+ 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/>.
+ 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 FILE_STREAM_CREATOR_H
@@ -24,11 +24,8 @@
class FileStreamCreator : public LogStreamCreator
{
- public:
- virtual LogStream* create (FiltersFactory* filtersFactory,
- string location,
- list<string>& filters,
- u_long cycleLog);
+public:
+ virtual LogStream* create (FiltersFactory*, string, list<string>&, u_long);
};
#endif
Modified: trunk/myserver/include/log/stream/log_stream.h
===================================================================
--- trunk/myserver/include/log/stream/log_stream.h 2008-10-08 19:28:07 UTC
(rev 2873)
+++ trunk/myserver/include/log/stream/log_stream.h 2008-10-08 22:21:10 UTC
(rev 2874)
@@ -1,19 +1,19 @@
/* -*- mode: c++ -*- */
/*
-MyServer
-Copyright (C) 2006, 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.
+ MyServer
+ Copyright (C) 2006, 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.
+ 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/>.
+ 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 LOG_STREAM_H
@@ -25,172 +25,57 @@
#include <include/filter/filters_chain.h>
#include <include/filter/filters_factory.h>
#include <include/filter/stream.h>
+#include <include/base/sync/mutex.h>
+using namespace std;
-/*!
- * Defines some events of interest for LogStream objects.
- */
enum LogStreamEvent
-{
- EVT_SET_CYCLE_LOG,
- EVT_LOG,
- EVT_CLOSE,
- EVT_ADD_FILTER
-};
+ {
+ EVT_SET_CYCLE,
+ EVT_LOG,
+ EVT_CLOSE,
+ EVT_ADD_FILTER,
+ EVT_CHOWN,
+ EVT_ENTER_ERROR_MODE,
+ EVT_EXIT_ERROR_MODE
+ };
-
-using namespace std;
-
-
class LogStream
{
- public:
-
-
- /*!
- * The constructor.
- * \param filtersFactory An instance of FiltersFactory.
- * \param cycleLog The cycleLog value.
- * \param outStream The Stream where this LogStream will
- * write the log messages.
- * \param filtersChain The messages will pass through a
- * FiltersChain before being written to the Stream.
- */
- LogStream (FiltersFactory* filtersFactory,
- u_long cycleLog,
- Stream* outStream,
- FiltersChain* filtersChain);
-
-
- /*!
- * \return 0 on success.
- */
+public:
+ LogStream (FiltersFactory* ff, u_long cycle, Stream* out, FiltersChain* fc);
int addFilter (Filter* filter);
-
-
- /*!
- * \return 0 on success.
- */
int removeFilter (Filter* filter);
-
-
- /*!
- * \return 0 on success.
- */
int update (LogStreamEvent evt, void* message = 0, void* reply = 0);
-
-
- /*!
- * \return 0 on success.
- */
int close ();
-
-
- /*!
- * \return 0 the close method was called.
- */
int getIsOpened ();
-
-
u_long getLatestWrittenBytes ();
-
-
- virtual u_long streamSize ();
-
-
- u_long getCycleLog ();
-
-
+ u_long getCycle ();
Stream* getOutStream ();
-
-
FiltersFactory const* getFiltersFactory ();
-
-
FiltersChain* getFiltersChain ();
-
-
- void setCycleLog (u_long cycleLog);
-
-
- /*!
- * Check if we have reached the max allowed size for the log.
- * \return 0 if there is no need to cycle the log yet.
- */
+ int setCycle (u_long cycle);
int needToCycle ();
-
-
- /*!
- * \return 0 on success.
- */
+ list<string>& getCycledStreams ();
virtual int log (string message);
-
-
+ virtual u_long streamSize ();
+ virtual int chown (int uid, int gid);
+ virtual int enterErrorMode ();
+ virtual int exitErrorMode ();
virtual ~LogStream ();
-
-
- list<string>& getCycledStreams ();
-
-
- protected:
-
-
- /*!
- * \return 0 on success.
- */
+protected:
virtual int streamCycle ();
-
-
- /*!
- * Flushes any remaining data in the FiltersChain, cycle the stream
- * and recreates all filters.
- * \return 0 on success.
- */
int doCycle ();
-
-
- /*!
- * \return 0 on success.
- */
int write (string message);
-
-
- /*!
- * \return 0 on success.
- */
int resetFilters ();
-
-
- /*!
- * The latest number of bytes written to the Stream.
- */
u_long nbw;
-
-
- /*!
- * A zero value means `never cycle'. A non-zero value establishes
- * the maximum size allowed for the LogStream's growth before
- * cycling it.
- */
- u_long cycleLog;
-
-
- /*!
- * Will be zero after a successful call to the close method.
- */
+ u_long cycle;
int isOpened;
-
-
- FiltersChain* filtersChain;
-
-
- Stream* outStream;
-
-
- FiltersFactory* filtersFactory;
-
-
+ FiltersChain* fc;
+ Stream* out;
+ FiltersFactory* ff;
list<string> cycledStreams;
+ Mutex* mutex;
};
#endif
Modified: trunk/myserver/include/log/stream/log_stream_creator.h
===================================================================
--- trunk/myserver/include/log/stream/log_stream_creator.h 2008-10-08
19:28:07 UTC (rev 2873)
+++ trunk/myserver/include/log/stream/log_stream_creator.h 2008-10-08
22:21:10 UTC (rev 2874)
@@ -1,19 +1,19 @@
/* -*- mode: c++ -*- */
/*
-MyServer
-Copyright (C) 2006, 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.
+ MyServer
+ Copyright (C) 2006, 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.
+ 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/>.
+ 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 LOG_STREAM_CREATOR_H
@@ -27,17 +27,8 @@
class LogStreamCreator
{
- public:
-
-
- /*!
- * Create a new instance of a concrete LogStream. If something
- * of wrong happens, it must return 0.
- */
- virtual LogStream* create (FiltersFactory* filtersFactory,
- string location,
- list<string>& filters,
- u_long cycleLog) = 0;
+public:
+ virtual LogStream* create (FiltersFactory*, string, list<string>&, u_long) =
0;
};
#endif
Modified: trunk/myserver/include/log/stream/log_stream_factory.h
===================================================================
--- trunk/myserver/include/log/stream/log_stream_factory.h 2008-10-08
19:28:07 UTC (rev 2873)
+++ trunk/myserver/include/log/stream/log_stream_factory.h 2008-10-08
22:21:10 UTC (rev 2874)
@@ -1,19 +1,19 @@
/* -*- mode: c++ -*- */
/*
-MyServer
-Copyright (C) 2006, 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.
+ MyServer
+ Copyright (C) 2006, 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.
+ 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/>.
+ 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 LOG_STREAM_FACTORY_H
@@ -34,80 +34,14 @@
class LogStreamFactory
{
public:
-
-
- /*!
- * This constructor initializes the logStreamCreators map. To
- * add more LogStreams, you have to create a new class implementing
- * the LogStreamCreator interface and then add it here providing
- * a valid protocol string (in the form protocol://) as key.
- */
LogStreamFactory ();
-
-
- /*!
- * The destructor. Ensures that the memory allocated for
- * all the LogStreamCreator objects gets freed.
- */
~LogStreamFactory ();
-
-
- /*!
- * Factory method. Creates a new concrete LogStream.
- * \param filtersFactory Self explicating.
- * \param location This is the path where the LogStream will point to.
- * The location string must follow the syntax `protocol://path/to/log'.
- * The protocol:// part can't be missing, since it is required to get
- * the proper constructor for the new object that will be created.
- * \param filters A list of strings representing filters to be used within
- * the new LogStream.
- * \param cycleLog Whether the log should be cycled or not. 0 means never
- * cycle.
- * \return A new instance of one of LogStream subclasses or 0 if
- * the location string does not contain a protocol known by the
- * LogStreamFactory or if something of wrong happened during the LogStream
- * creation.
- */
- LogStream* createLogStream (FiltersFactory* filtersFactory,
- string location,
- list<string>& filters,
- u_long cycleLog);
-
-
- /*!
- * Get the protocol part of a location string.
- * \param location The string representing a valid location as explained
- * in createLogStream method description.
- * \return A new string with the protocol part of the location, an empty
- * string if an invalid protocol was detected.
- */
+ LogStream* create (FiltersFactory*, string, list<string>&, u_long);
string getProtocol (string location);
-
-
- /*!
- * Get the path part of a location string.
- * \param location The string representing a valid location as explained
- * in createLogStream method description.
- * \return A new string with the path part of the location, an empty
- * string is an invalid protocol was detected.
- */
string getPath (string location);
-
-
- /*!
- * Checks whether `protocol' is between those known by the LogStreamFactory.
- * \return true If it is.
- */
- bool protocolCheck (string protocol);
-
-
+ bool protocolCheck (string protocol);
private:
-
-
- /*!
- * Holds all the constructors known by the LogStreamFactory.
- */
- map<string, LogStreamCreator*> logStreamCreators;
+ map<string, LogStreamCreator*> creators;;
};
#endif
Modified: trunk/myserver/include/log/stream/socket_stream.h
===================================================================
--- trunk/myserver/include/log/stream/socket_stream.h 2008-10-08 19:28:07 UTC
(rev 2873)
+++ trunk/myserver/include/log/stream/socket_stream.h 2008-10-08 22:21:10 UTC
(rev 2874)
@@ -1,19 +1,19 @@
/* -*- mode: c++ -*- */
/*
-MyServer
-Copyright (C) 2006, 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.
+ MyServer
+ Copyright (C) 2006, 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.
+ 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/>.
+ 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 SOCKET_STREAM_H
@@ -27,7 +27,7 @@
class SocketStream : public LogStream
{
- public:
+public:
SocketStream (FiltersFactory* filtersFactory,
u_long cycleLog,
Modified: trunk/myserver/include/log/stream/socket_stream_creator.h
===================================================================
--- trunk/myserver/include/log/stream/socket_stream_creator.h 2008-10-08
19:28:07 UTC (rev 2873)
+++ trunk/myserver/include/log/stream/socket_stream_creator.h 2008-10-08
22:21:10 UTC (rev 2874)
@@ -1,19 +1,19 @@
/* -*- mode: c++ -*- */
/*
-MyServer
-Copyright (C) 2006, 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.
+ MyServer
+ Copyright (C) 2006, 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.
+ 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/>.
+ 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 SOCKET_STREAM_CREATOR_H
@@ -26,22 +26,9 @@
class SocketStreamCreator : public LogStreamCreator
{
- public:
- virtual LogStream* create (FiltersFactory* filtersFactory,
- string location,
- list<string>& filters,
- u_long cycleLog);
-
-
- /*!
- * A helper method to get the port part of an URL.
- */
+public:
+ virtual LogStream* create (FiltersFactory*, string, list<string>&, u_long);
u_short getPort (string location);
-
-
- /*!
- * A helper method to get the host part of an URL.
- */
string getHost (string location);
};
Modified: trunk/myserver/include/server/server.h
===================================================================
--- trunk/myserver/include/server/server.h 2008-10-08 19:28:07 UTC (rev
2873)
+++ trunk/myserver/include/server/server.h 2008-10-08 22:21:10 UTC (rev
2874)
@@ -53,6 +53,7 @@
#include <string>
#include <list>
+
using namespace std;
/*!
@@ -61,7 +62,7 @@
#ifdef WIN32
unsigned int __stdcall listenServer(void* pParam);
#endif
-#ifdef NOT_WIN
+#ifdef NO_WIN
void* listenServer(void* pParam);
#endif
@@ -132,14 +133,14 @@
void stop();
void finalCleanup();
int terminate();
- int logWriteln(const char*);
+ int logWriteln(char const*, LoggingLevel level = WARNING);
int logWriteln(string const &str)
{return logWriteln(str.c_str());};
int logPreparePrintError();
int logEndPrintError();
int logLockAccess();
int logUnlockAccess();
- int setLogFile(char*);
+ int setLogLocation(string);
u_long getBuffersize();
u_long getBuffersize2();
u_long getThrottlingRate();
@@ -189,6 +190,7 @@
void loadPlugins();
void displayBoot();
int postLoad();
+ void initLogManager ();
CachedFileFactory cachedFiles;
@@ -212,7 +214,7 @@
bool toReboot;
bool rebooting;
- LogManager logManager;
+ LogManager* logManager;
bool serverReady;
u_long verbosity;
u_long throttlingRate;
@@ -236,7 +238,7 @@
u_long connectionTimeout;
u_long maxLogFileSize;
int copyConfigurationFromDefault(const char *);
- void logWriteNTimes(const char *, unsigned);
+ void logWriteNTimes(string, unsigned);
int checkConfigurationPaths();
bool resetConfigurationPaths(string &, string &, string &, string &, string
&);
Mutex* connectionsMutex;
@@ -262,7 +264,7 @@
ConnectionsScheduler connectionsScheduler;
ListenThreads listenThreads;
bool endServer;
-
+ string logLocation;
AuthMethodFactory authMethodFactory;
ValidatorFactory validatorFactory;
SecurityManager securityManager;
Modified: trunk/myserver/src/base/process/process_server_manager.cpp
===================================================================
--- trunk/myserver/src/base/process/process_server_manager.cpp 2008-10-08
19:28:07 UTC (rev 2873)
+++ trunk/myserver/src/base/process/process_server_manager.cpp 2008-10-08
22:21:10 UTC (rev 2874)
@@ -102,12 +102,7 @@
ostringstream msg;
msg << "Error: incomplete remote PROCESS_SERVER block, "
<< domain << ":" << name << " needs a port";
- ::Server::getInstance()->logLockAccess();
- ::Server::getInstance()->logPreparePrintError();
- ::Server::getInstance()->logWriteln(msg.str().c_str());
- ::Server::getInstance()->logEndPrintError();
- ::Server::getInstance()->logUnlockAccess();
-
+ ::Server::getInstance()->logWriteln(msg.str().c_str(), ERROR);
}
}
@@ -115,11 +110,7 @@
else
{
const char *msg = "Error: incomplete PROCESS_SERVER block";
- ::Server::getInstance()->logLockAccess();
- ::Server::getInstance()->logPreparePrintError();
- ::Server::getInstance()->logWriteln(msg);
- ::Server::getInstance()->logEndPrintError();
- ::Server::getInstance()->logUnlockAccess();
+ ::Server::getInstance()->logWriteln(msg, ERROR);
}
}
@@ -391,11 +382,7 @@
ostringstream stream;
stream << "Cannot run process " << path
<< ": Reached max number of servers";
- ::Server::getInstance()->logLockAccess();
- ::Server::getInstance()->logPreparePrintError();
- ::Server::getInstance()->logWriteln(stream.str().c_str());
- ::Server::getInstance()->logEndPrintError();
- ::Server::getInstance()->logUnlockAccess();
+ ::Server::getInstance()->logWriteln(stream.str().c_str(), ERROR);
return 1;
}
Modified: trunk/myserver/src/conf/mime/mime_manager.cpp
===================================================================
--- trunk/myserver/src/conf/mime/mime_manager.cpp 2008-10-08 19:28:07 UTC
(rev 2873)
+++ trunk/myserver/src/conf/mime/mime_manager.cpp 2008-10-08 22:21:10 UTC
(rev 2874)
@@ -650,11 +650,7 @@
error.assign("Warning: multiple MIME types registered for the extension
" );
error.append(nmr->extension);
- Server::getInstance()->logLockAccess();
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(error.c_str());
- Server::getInstance()->logEndPrintError();
- Server::getInstance()->logUnlockAccess();
+ Server::getInstance()->logWriteln(error.c_str(), ERROR);
delete old;
}
}
Modified: trunk/myserver/src/conf/vhost/vhost.cpp
===================================================================
--- trunk/myserver/src/conf/vhost/vhost.cpp 2008-10-08 19:28:07 UTC (rev
2873)
+++ trunk/myserver/src/conf/vhost/vhost.cpp 2008-10-08 22:21:10 UTC (rev
2874)
@@ -1,18 +1,18 @@
/*
-MyServer
-Copyright (C) 2002, 2003, 2004, 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.
+ MyServer
+ Copyright (C) 2002, 2003, 2004, 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.
+ 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/>.
+ 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/conf/vhost/vhost.h>
@@ -33,15 +33,13 @@
/*!
*vhost costructor
*/
-Vhost::Vhost()
+Vhost::Vhost(LogManager* lm)
{
ipList.clear();
hostList.clear();
refMutex.init();
documentRoot.assign("");
systemRoot.assign("");
- accessesLogFileName.assign("");
- warningsLogFileName.assign("");
hashedData.clear();
protocolData = 0;
@@ -54,6 +52,7 @@
refCount = 0;
nullReferenceCb = 0;
defaultPriority = 0;
+ logManager = lm;
}
@@ -69,20 +68,10 @@
freeSSL();
freeHashedData();
refMutex.destroy();
- accessesLogFileName.assign("");
-
- warningsLogFileName.assign("");
-
- warningsLogFile->close();
- accessesLogFile->close();
-
- delete warningsLogFile;
- delete accessesLogFile;
-
documentRoot.assign("");
systemRoot.assign("");
-
mimeManager.clean();
+ logManager->remove (this);
}
/*!
@@ -92,18 +81,18 @@
int Vhost::freeHashedData()
{
try
- {
- HashMap<string, string*>::Iterator it = hashedData.begin();
- for (;it != hashedData.end(); it++)
{
- delete (*it);
+ HashMap<string, string*>::Iterator it = hashedData.begin();
+ for (;it != hashedData.end(); it++)
+ {
+ delete (*it);
+ }
+ hashedData.clear();
}
- hashedData.clear();
- }
catch(...)
- {
- return 1;
- }
+ {
+ return 1;
+ }
return 0;
}
@@ -130,11 +119,11 @@
{
list<StringRegex*>::iterator i = hostList.begin();
while(i != hostList.end())
- {
- StringRegex* sr = *i;
- delete sr;
- i++;
- }
+ {
+ StringRegex* sr = *i;
+ delete sr;
+ i++;
+ }
hostList.clear();
}
@@ -145,66 +134,31 @@
{
list<StringRegex*>::iterator i = ipList.begin();
while(i != ipList.end())
- {
- StringRegex* sr = *i;
- delete sr;
- i++;
- }
+ {
+ StringRegex* sr = *i;
+ delete sr;
+ i++;
+ }
hostList.clear();
}
+int
+Vhost::openAccessLog (string location, list<string>& filters, u_long cycle)
+{
+ return logManager->add (this, "ACCESSLOG", location, filters, cycle);
+}
-/*!
- *Open the log files for the virtual hosts.
- *\param maxLogSize Define a max log size for the opened files.
- */
-int Vhost::openLogFiles(u_long maxlogSize)
+int
+Vhost::openWarningLog (string location, list<string>& filters, u_long cycle)
{
- const char* accessesLogFileName = getAccessesLogFileName();
- const char* warningsLogFileName = getWarningsLogFileName();
+ return logManager->add (this, "WARNINGLOG", location, filters, cycle);
+}
- accessesLogFile = new LogManager();
- warningsLogFile = new LogManager();
-
- if(accessesLogFileName)
- {
- accessesLogFile->load(accessesLogFileName);
-
- if(strstr(getAccessLogOpt(), "cycle=yes"))
- {
- accessesLogFile->setCycleLog(1);
- }
- if(strstr(getAccessLogOpt(), "cycle_gzip=no"))
- {
- accessesLogFile->setGzip(0);
- }
- else
- {
- accessesLogFile->setGzip(1);
- }
- }
-
- if(warningsLogFileName)
- {
- warningsLogFile->load(warningsLogFileName);
- if(strstr(getWarningLogOpt(), "cycle=yes"))
- {
- warningsLogFile->setCycleLog(1);
- }
-
- if(strstr(getWarningLogOpt(), "cycle_gzip=no"))
- {
- warningsLogFile->setGzip(0);
- }
- else
- {
- warningsLogFile->setGzip(1);
- }
- }
-
- setMaxLogSize(maxlogSize);
-
- return 0;
+int
+Vhost::openLogFiles ()
+{
+ return logManager->count (this, "ACCESSLOG") == 0 ||
+ logManager->count (this, "WARNINGLOG") == 0;
}
/*!
@@ -231,19 +185,19 @@
list<StringRegex*>::iterator i = ipList.begin();
while(i != ipList.end())
- {
- StringRegex* sr = *i;
- /*
- *If this is the virtual host with the right IP.
- */
- if(!stringcmp(sr->name,ip))
{
- ipList.erase(i);
- return;
- }
+ StringRegex* sr = *i;
+ /*
+ *If this is the virtual host with the right IP.
+ */
+ if(!stringcmp(sr->name,ip))
+ {
+ ipList.erase(i);
+ return;
+ }
- i++;
- }
+ i++;
+ }
}
/*!
@@ -255,19 +209,19 @@
list<StringRegex*>::iterator i = hostList.begin();
while(i != hostList.end())
- {
- StringRegex* sr = *i;
- /*
- *If this is the virtual host with the right IP.
- */
- if(!stringcmp(sr->name, host))
{
- hostList.erase(i);
- return;
- }
+ StringRegex* sr = *i;
+ /*
+ *If this is the virtual host with the right IP.
+ */
+ if(!stringcmp(sr->name, host))
+ {
+ hostList.erase(i);
+ return;
+ }
- i++;
- }
+ i++;
+ }
}
/*!
*Check if an host is allowed to the connection
@@ -281,22 +235,22 @@
list<StringRegex*>::iterator i = hostList.begin();
while(i != hostList.end())
- {
- StringRegex* sr = *i;
- regmatch_t pm;
- if(sr->regex.isCompiled())
{
- if (!sr->regex.exec(host, 1, &pm, REG_NOTBOL))
- {
- return 1;
- }
- }
+ StringRegex* sr = *i;
+ regmatch_t pm;
+ if(sr->regex.isCompiled())
+ {
+ if (!sr->regex.exec(host, 1, &pm, REG_NOTBOL))
+ {
+ return 1;
+ }
+ }
- if(!stringcmp(sr->name, host))
- return 1;
+ if(!stringcmp(sr->name, host))
+ return 1;
- i++;
- }
+ i++;
+ }
return 0;
}
@@ -327,28 +281,28 @@
*/
int Vhost::isIPAllowed(const char* ip)
{
- /* If no IPs are specified then every host is allowed to connect here. */
+ /* If no IPs are specified then every host is allowed to connect here. */
if(!ipList.size() || !ip)
return 1;
list<StringRegex*>::iterator i = ipList.begin();
while(i != ipList.end())
- {
- StringRegex* sr = *i;
- regmatch_t pm;
- if(sr->regex.isCompiled())
{
- if (!sr->regex.exec(ip ,1, &pm, REG_NOTBOL))
- {
- return 1;
- }
- }
+ StringRegex* sr = *i;
+ regmatch_t pm;
+ if(sr->regex.isCompiled())
+ {
+ if (!sr->regex.exec(ip ,1, &pm, REG_NOTBOL))
+ {
+ return 1;
+ }
+ }
- if(!stringcmp(sr->name, ip))
- return 1;
+ if(!stringcmp(sr->name, ip))
+ return 1;
- i++;
- }
+ i++;
+ }
return 0;
}
@@ -370,20 +324,20 @@
uint32_t* ucs4 = stringprep_utf8_to_ucs4 (host, -1, &len);
if(!ucs4)
- {
- delete hl;
- return;
- }
+ {
+ delete hl;
+ return;
+ }
ret = idna_to_ascii_4z (ucs4, &ascii, 0);
free(ucs4);
if (ret != IDNA_SUCCESS)
- {
- delete hl;
- return;
- }
+ {
+ delete hl;
+ return;
+ }
host = ascii;
#endif
@@ -401,127 +355,30 @@
}
/*!
- *Here threads get the permission to use the access log file.
- *\param id The caller thread ID.
+ * Write to the accesses log.
+ * \param str The line to log.
*/
-u_long Vhost::accessesLogRequestAccess(int id)
+int
+Vhost::accessesLogWrite (const char* str)
{
- accessesLogFile->requestAccess();
- return 0;
+ return logManager->log (this, "ACCESSLOG", string (str));
}
/*!
- *Here threads get the permission to use the warnings log file.
- *\param id The caller thread ID.
+ * Write a line to the warnings log.
+ * \param str The line to log.
*/
-u_long Vhost::warningsLogRequestAccess(int id)
+int
+Vhost::warningsLogWrite (const char* str)
{
- warningsLogFile->requestAccess();
- return 0;
-}
-
-/*!
- *Here threads release the permission to use the access log file.
- *\param id The caller thread ID.
- */
-u_long Vhost::accessesLogTerminateAccess(int id)
-{
- accessesLogFile->terminateAccess();
- return 0;
-}
-
-/*!
- *Here threads release the permission to use the warnings log file.
- *\param id The caller thread ID.
- */
-u_long Vhost::warningsLogTerminateAccess(int id)
-{
- warningsLogFile->terminateAccess();
- return 0;
-}
-
-/*!
- *Write to the accesses log file.
- *\param str The line to log.
- */
-int Vhost::accessesLogWrite(const char* str)
-{
- return accessesLogFile->write(str);
-}
-
-/*!
- *Return a pointer to the file used by the accesses log.
- */
-File* Vhost::getAccessesLogFile()
-{
- return accessesLogFile->getFile();
-}
-
-/*!
- *Get the log object for the warnings.
- */
-LogManager* Vhost::getWarningsLog()
-{
- return warningsLogFile;
-}
-
-/*!
- *Get the log object for the accesses.
- */
-LogManager* Vhost::getAccessesLog()
-{
- return accessesLogFile;
-}
-
-/*!
- *Write a line to the warnings log file.
- *\param str The line to log.
- */
-int Vhost::warningsLogWrite(const char* str)
-{
string msg;
- getLocalLogFormatDate(msg, 100);
- msg.append(" -- ");
- msg.append(str);
-#ifdef WIN32
- msg.append("\r\n");
-#else
- msg.append("\n");
-#endif
- return warningsLogFile->write(msg.c_str());
+ getLocalLogFormatDate (msg, 100);
+ msg.append (" -- ");
+ msg.append (str);
+ return logManager->log (this, "WARNINGLOG", string (str), true);
}
/*!
- *Return a pointer to the file used by the warnings log.
- */
-File* Vhost::getWarningsLogFile()
-{
- return warningsLogFile->getFile();
-}
-
-/*!
- *Set the max size of the log files.
- *\param newSize The new max dimension to use for the warning log files.
- */
-void Vhost::setMaxLogSize(int newSize)
-{
- warningsLogFile->setMaxSize(newSize);
- accessesLogFile->setMaxSize(newSize);
-}
-
-/*!
- *Get the max size of the log files. Return 0 on success.
- */
-int Vhost::getMaxLogSize()
-{
- /*
- *warningsLogFile max log size is equal to the
- *accessesLogFile one.
- */
- return warningsLogFile->getMaxSize( );
-}
-
-/*!
*Set the null reference callback function. It is called when the reference
*counter for the virtual host is zero.
*\param cb The null references callback function.
Modified: trunk/myserver/src/conf/vhost/vhost_manager.cpp
===================================================================
--- trunk/myserver/src/conf/vhost/vhost_manager.cpp 2008-10-08 19:28:07 UTC
(rev 2873)
+++ trunk/myserver/src/conf/vhost/vhost_manager.cpp 2008-10-08 22:21:10 UTC
(rev 2874)
@@ -1,18 +1,18 @@
/*
-MyServer
-Copyright (C) 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.
+ MyServer
+ Copyright (C) 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.
+ 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/>.
+ 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/conf/vhost/vhost_manager.h>
#include <include/conf/vhost/vhost.h>
@@ -35,80 +35,34 @@
listenThreads->addListeningThread(vh->getPort());
if(extSource)
- {
- int ret = extSource->addVHost(vh);
- mutex.unlock();
- return ret;
- }
+ {
+ int ret = extSource->addVHost(vh);
+ mutex.unlock();
+ return ret;
+ }
it = hostList.begin();
try
- {
- for(;it != hostList.end(); it++)
{
- hostl = *it;
-
- /* Do not do a case sensitive compare under windows. */
-#ifdef WIN32
- if(!stringcmpi(vh->getAccessesLogFileName(),
- hostl->getAccessesLogFileName()))
-#else
- if(!stringcmp(vh->getAccessesLogFileName(),
- hostl->getAccessesLogFileName()))
-#endif
+ if(!vh->getProtocolName())
{
string error;
- error.assign("Warning: multiple hosts use the same log file:" );
- error.append(vh->getAccessesLogFileName());
- Server::getInstance()->logLockAccess();
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(error.c_str());
- Server::getInstance()->logEndPrintError();
- Server::getInstance()->logUnlockAccess();
+ error.assign("Warning: protocol not defined for virtual host: " );
+ error.append(vh->getName());
+ error.append(", using HTTP by default");
+ vh->setProtocolName("http");
+ Server::getInstance()->logWriteln(error.c_str(), ERROR);
}
-
-#ifdef WIN32
- if(!stringcmpi(vh->getWarningsLogFileName(),
- hostl->getWarningsLogFileName()))
-#else
- if(!stringcmp(vh->getWarningsLogFileName(),
- hostl->getWarningsLogFileName()))
-#endif
- {
- string error;
- error.assign("Warning: multiple hosts use the same log file:" );
- error.append(vh->getWarningsLogFileName());
- Server::getInstance()->logLockAccess();
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(error.c_str());
- Server::getInstance()->logEndPrintError();
- Server::getInstance()->logUnlockAccess();
- }
+ hostList.push_back(vh);
+ mutex.unlock();
+ return 0;
}
-
- if(!vh->getProtocolName())
+ catch(...)
{
- string error;
- error.assign("Warning: protocol not defined for virtual host: " );
- error.append(vh->getName());
- error.append(", using HTTP by default");
- vh->setProtocolName("http");
- Server::getInstance()->logLockAccess();
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(error.c_str());
- Server::getInstance()->logEndPrintError();
- Server::getInstance()->logUnlockAccess();
- }
- hostList.push_back(vh);
- mutex.unlock();
- return 0;
- }
- catch(...)
- {
- mutex.unlock();
- return -1;
- };
+ mutex.unlock();
+ return -1;
+ };
}
/*!
@@ -125,57 +79,58 @@
mutex.lock();
try
- {
- if(extSource)
{
- Vhost* ret = extSource->getVHost(host, ip, port);
- mutex.unlock();
- return ret;
- }
+ if(extSource)
+ {
+ Vhost* ret = extSource->getVHost(host, ip, port);
+ mutex.unlock();
+ return ret;
+ }
- it = hostList.begin();
+ it = hostList.begin();
- /*Do a linear search here. We have to use the first full-matching
- *virtual host.
- */
- for(; it != hostList.end(); it++)
- {
- Vhost* vh = *it;
- /* Control if the host port is the correct one. */
- if(vh->getPort() != port)
- continue;
- /* If ip is defined check that it is allowed to connect to the host. */
- if(ip && !vh->isIPAllowed(ip))
- continue;
- /* If host is defined check if it is allowed to connect to the host. */
- if(host && !vh->isHostAllowed(host))
- continue;
- /* We find a valid host. */
+ /*Do a linear search here. We have to use the first full-matching
+ *virtual host.
+ */
+ for(; it != hostList.end(); it++)
+ {
+ Vhost* vh = *it;
+ /* Control if the host port is the correct one. */
+ if(vh->getPort() != port)
+ continue;
+ /* If ip is defined check that it is allowed to connect to the host.
*/
+ if(ip && !vh->isIPAllowed(ip))
+ continue;
+ /* If host is defined check if it is allowed to connect to the host.
*/
+ if(host && !vh->isHostAllowed(host))
+ continue;
+ /* We find a valid host. */
+ mutex.unlock();
+ /* Add a reference. */
+ vh->addRef();
+ return vh;
+ }
mutex.unlock();
- /* Add a reference. */
- vh->addRef();
- return vh;
+ return 0;
}
- mutex.unlock();
- return 0;
- }
catch(...)
- {
- mutex.unlock();
- return 0;
- };
+ {
+ mutex.unlock();
+ return 0;
+ };
}
/*!
*VhostManager costructor.
*\param lt A ListenThreads object to use to create new threads.
*/
-VhostManager::VhostManager(ListenThreads* lt)
+VhostManager::VhostManager(ListenThreads* lt, LogManager* lm)
{
listenThreads = lt;
hostList.clear();
extSource = 0;
mutex.init();
+ logManager = lm;
}
/*!
@@ -190,19 +145,19 @@
it = hostList.begin();
try
- {
- for(;it != hostList.end(); it++)
- delete *it;
+ {
+ for(;it != hostList.end(); it++)
+ delete *it;
- hostList.clear();
+ hostList.clear();
- mutex.unlock();
- }
+ mutex.unlock();
+ }
catch(...)
- {
- mutex.unlock();
- return;
- };
+ {
+ mutex.unlock();
+ return;
+ };
}
/*!
@@ -223,61 +178,53 @@
}
/*!
- *Change the file owner for the log files.
+ *Change the file owner for the log locations.
*/
-void VhostManager::changeFilesOwner()
+void VhostManager::changeLocationsOwner ()
{
if(Server::getInstance()->getUid() | Server::getInstance()->getGid())
- {
- int uid = Server::getInstance()->getUid();
- int gid = Server::getInstance()->getGid();
+ {
+ int uid = Server::getInstance()->getUid();
+ int gid = Server::getInstance()->getGid();
- /*
- *Change the user and group identifier to -1
- *if they are not specified.
- */
- if(!uid)
- uid = -1;
+ /*
+ *Change the user and group identifier to -1
+ *if they are not specified.
+ */
+ if(!uid)
+ uid = -1;
- if(!gid)
- gid = -1;
+ if(!gid)
+ gid = -1;
- /*
- *Change the log files owner if a different user or group
- *identifier is specified.
- */
- for(int i = 0; ; i++)
- {
- int err;
- Vhost* vh = getVHostByNumber(i);
- /* Break if we reach the end of the list. */
- if(!vh)
- break;
+ /*
+ *Change the log files owner if a different user or group
+ *identifier is specified.
+ */
+ for(int i = 0; ; i++)
+ {
+ int err;
+ Vhost* vh = getVHostByNumber(i);
+ /* Break if we reach the end of the list. */
+ if(!vh)
+ break;
- /* Chown the log files. */
- err = FilesUtility::chown(vh->getAccessesLogFileName(), uid, gid);
- if(err)
- {
- string str;
- str.assign("Error changing owner for: ");
- str.append(vh->getAccessesLogFileName());
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(str);
- Server::getInstance()->logEndPrintError();
- }
+ /* Chown the log files. */
+ err = logManager->chown (vh, "ACCESSLOG", uid, gid);
+ if(err)
+ {
+ string str ("Error changing owner for accesses log locations");
+ Server::getInstance()->logWriteln(str.c_str (), ERROR);
+ }
- err = FilesUtility::chown(vh->getWarningsLogFileName(), uid, gid);
- if(err)
- {
- string str;
- str.assign("Error changing owner for: ");
- str.append(vh->getWarningsLogFileName());
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(str);
- Server::getInstance()->logEndPrintError();
- }
+ err = logManager->chown (vh, "WARNINGLOG", uid, gid);
+ if(err)
+ {
+ string str ("Error changing owner for errors log locations");
+ Server::getInstance()->logWriteln(str.c_str (), ERROR);
+ }
+ }
}
- }
}
@@ -289,333 +236,391 @@
return hostList.size();
}
+string
+VhostManager::saveXMLlogData (string name, Vhost* vh)
+{
+ list<string> l;
+ ostringstream oss;
+ if (!logManager->get (vh, name, &l))
+ {
+ list<string>::iterator it;
+ oss << "<STREAMS>\r\n";
+ for (it = l.begin (); it != l.end (); it++)
+ {
+ oss << "<STREAM>\r\n";
+ oss << "<LOCATION>";
+ oss << *it;
+ oss << "</LOCATION>\r\n";
+ u_long cycle = 0;
+ if (!logManager->getCycle (*it, &cycle))
+ {
+ oss << "<CYCLE>";
+ oss << cycle;
+ oss << "</CYCLE>\r\n";
+ }
+ list<string> f;
+ if (!logManager->getFilters (*it, &f))
+ {
+ oss << "<FILTERS>\r\n";
+ list<string>::iterator it_1;
+ for (it_1 = f.begin (); it_1 != f.end (); it_1++)
+ {
+ oss << "<FILTER>";
+ oss << *it_1;
+ oss << "</FILTER>\r\n";
+ }
+ oss << "</FILTERS>\r\n";
+ }
+ oss << "</STREAM>\r\n";
+ }
+ oss << "</STREAMS>\r\n";
+ }
+ return oss.str ();
+}
+
+void
+VhostManager::loadXMLlogData (string name, Vhost* vh, xmlNode* lcur)
+{
+ xmlAttr *attr;
+ string opt;
+ attr = lcur->properties;
+ while (attr)
+ {
+ opt.append((char*)attr->name);
+ opt.append("=");
+ opt.append((char*)attr->children->content);
+ if(attr->next)
+ {
+ opt.append(",");
+ }
+ attr = attr->next;
+ }
+ string location;
+ list<string> filters;
+ u_long cycle;
+ xmlNode* streams = lcur->children;
+ for (; streams->next; streams = streams->next)
+ {
+ if (streams->type == XML_ELEMENT_NODE &&
+ !xmlStrcmp (streams->name, (const xmlChar*)"STREAMS"))
+ {
+ xmlNode* currStream = streams->children;
+ for (; currStream->next; currStream = currStream->next)
+ {
+ if (currStream->type == XML_ELEMENT_NODE &&
+ !xmlStrcmp (currStream->name, (const xmlChar*)"STREAM"))
+ {
+ xmlNode* parameters = currStream->children;
+ location.assign ("");
+ filters.clear ();
+ cycle = 0;
+ for (; parameters->next; parameters = parameters->next)
+ {
+ if (parameters->type == XML_ELEMENT_NODE)
+ {
+ if (!xmlStrcmp (parameters->name,
+ (const xmlChar*)"LOCATION"))
+ {
+ if (parameters->children &&
+ parameters->children->content)
+ {
+ location.assign
((char*)parameters->children->content);
+ }
+ }
+ else if (!xmlStrcmp (parameters->name,
+ (const xmlChar*)"CYCLE"))
+ {
+ if (parameters->children &&
+ parameters->children->content)
+ {
+ cycle = atoi
((char*)parameters->children->content);
+ }
+ }
+ else if (!xmlStrcmp (parameters->name,
+ (const xmlChar*)"FILTERS"))
+ {
+ xmlNode* filterList = parameters->children;
+ for (; filterList; filterList = filterList->next)
+ {
+ if (filterList->type == XML_ELEMENT_NODE)
+ {
+ if (!xmlStrcmp (filterList->name,
+ (const
xmlChar*)"FILTER"))
+ {
+ if (filterList->children &&
+ filterList->children->content)
+ {
+ string filter
((char*)filterList->children->content);
+ filters.push_back (filter);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ int err = 1;
+ string str ("VhostManager::loadXMLlogData : Unrecognized log
type");
+
+ if (!name.compare ("ACCESSLOG"))
+ {
+ err = vh->openAccessLog (location, filters, cycle);
+ vh->setAccessLogOpt (opt.c_str ());
+ str.assign ("Error opening accesses log location " +
location);
+ }
+ else if (!name.compare ("WARNINGLOG"))
+ {
+ err = vh->openWarningLog (location, filters, cycle);
+ vh->setWarningLogOpt (opt.c_str ());
+ str.assign ("Error opening warnings log location " +
location);
+ }
+ if (err)
+ {
+ Server::getInstance ()->logWriteln (str.c_str (), ERROR);
+ }
+ }
+ }
+ }
+ }
+}
+
/*!
*Load the virtual hosts from a XML configuration file
*Returns non-null on errors.
*\param filename The XML file to open.
*\param maxlogSize The maximum dimension for the log file.
*/
-int VhostManager::loadXMLConfigurationFile(const char *filename,
- int maxlogSize)
+int VhostManager::loadXMLConfigurationFile(const char *filename)
{
XmlParser parser;
xmlDocPtr doc;
xmlNodePtr node;
- string errMsg;
+ string errMsg;
if(parser.open(filename))
- {
- errMsg.assign("Error opening: ");
- errMsg.append(filename);
- Server::getInstance()->logLockAccess();
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(errMsg.c_str());
- Server::getInstance()->logEndPrintError();
- Server::getInstance()->logUnlockAccess();
- return -1;
- }
+ {
+ errMsg.assign("Error opening: ");
+ errMsg.append(filename);
+ Server::getInstance()->logWriteln(errMsg.c_str(), ERROR);
+ return -1;
+ }
doc = parser.getDoc();
node = doc->children->children;
for(;node;node = node->next )
- {
- xmlNodePtr lcur;
- Vhost *vh;
- if(xmlStrcmp(node->name, (const xmlChar *)"VHOST"))
- continue;
- lcur=node->children;
- vh=new Vhost();
- if(vh == 0)
{
- parser.close();
- clean();
- errMsg.assign("Error: allocating memory");
- Server::getInstance()->logLockAccess();
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(errMsg.c_str());
- Server::getInstance()->logEndPrintError();
- Server::getInstance()->logUnlockAccess();
- return -1;
- }
+ xmlNodePtr lcur;
+ Vhost *vh;
+ if(xmlStrcmp(node->name, (const xmlChar *)"VHOST"))
+ continue;
+ lcur=node->children;
+ vh=new Vhost(logManager);
+ if(vh == 0)
+ {
+ parser.close();
+ clean();
+ errMsg.assign("Error: allocating memory");
+ Server::getInstance()->logWriteln(errMsg.c_str(), ERROR);
+ return -1;
+ }
- SslContext* sslContext = vh->getVhostSSLContext();
+ SslContext* sslContext = vh->getVhostSSLContext();
- while(lcur)
- {
- if(!xmlStrcmp(lcur->name, (const xmlChar *)"HOST"))
- {
- int useRegex = 0;
- xmlAttr *attrs = lcur->properties;
- while(attrs)
+ while(lcur)
{
- if(!xmlStrcmp(attrs->name, (const xmlChar *)"isRegex"))
+ if(!xmlStrcmp(lcur->name, (const xmlChar *)"HOST"))
{
- if(attrs->children && attrs->children->content &&
- (!xmlStrcmp(attrs->children->content,
- (const xmlChar *)"YES")))
- {
- useRegex = 1;
- }
+ int useRegex = 0;
+ xmlAttr *attrs = lcur->properties;
+ while(attrs)
+ {
+ if(!xmlStrcmp(attrs->name, (const xmlChar *)"isRegex"))
+ {
+ if(attrs->children && attrs->children->content &&
+ (!xmlStrcmp(attrs->children->content,
+ (const xmlChar *)"YES")))
+ {
+ useRegex = 1;
+ }
+ }
+ attrs = attrs->next;
+ }
+
+ vh->addHost((const char*)lcur->children->content, useRegex);
}
- attrs = attrs->next;
- }
+ else if(!xmlStrcmp(lcur->name, (const xmlChar *)"NAME"))
+ {
+ vh->setName((char*)lcur->children->content);
+ }
+ else if(!xmlStrcmp(lcur->name, (const xmlChar *)"SSL_PRIVATEKEY"))
+ {
+ string pk((char*)lcur->children->content);
+ sslContext->setPrivateKeyFile(pk);
+ }
+ else if(!xmlStrcmp(lcur->name, (const xmlChar *)"SSL_CERTIFICATE"))
+ {
+ string certificate((char*)lcur->children->content);
+ sslContext->setCertificateFile(certificate);
+ }
+ else if(!xmlStrcmp(lcur->name, (const xmlChar
*)"CONNECTIONS_PRIORITY"))
+ {
+ vh->setDefaultPriority(atoi((const
char*)lcur->children->content));
- vh->addHost((const char*)lcur->children->content, useRegex);
- }
- else if(!xmlStrcmp(lcur->name, (const xmlChar *)"NAME"))
- {
- vh->setName((char*)lcur->children->content);
- }
- else if(!xmlStrcmp(lcur->name, (const xmlChar *)"SSL_PRIVATEKEY"))
- {
- string pk((char*)lcur->children->content);
- sslContext->setPrivateKeyFile(pk);
- }
- else if(!xmlStrcmp(lcur->name, (const xmlChar *)"SSL_CERTIFICATE"))
- {
- string certificate((char*)lcur->children->content);
- sslContext->setCertificateFile(certificate);
- }
- else if(!xmlStrcmp(lcur->name, (const xmlChar *)"CONNECTIONS_PRIORITY"))
- {
- vh->setDefaultPriority(atoi((const char*)lcur->children->content));
+ }
+ else if(!xmlStrcmp(lcur->name, (const xmlChar *)"SSL_PASSWORD"))
+ {
+ string pw;
+ if(lcur->children)
+ pw.assign((char*)lcur->children->content);
+ else
+ pw.assign("");
- }
- else if(!xmlStrcmp(lcur->name, (const xmlChar *)"SSL_PASSWORD"))
- {
- string pw;
- if(lcur->children)
- pw.assign((char*)lcur->children->content);
- else
- pw.assign("");
+ sslContext->setPassword(pw);
- sslContext->setPassword(pw);
-
- }
- else if(!xmlStrcmp(lcur->name, (const xmlChar *)"IP"))
- {
- int useRegex = 0;
- xmlAttr *attrs = lcur->properties;
- while(attrs)
- {
- if(!xmlStrcmp(attrs->name, (const xmlChar *)"isRegex"))
- {
- if(attrs->children && attrs->children->content &&
- (!xmlStrcmp(attrs->children->content,
- (const xmlChar *)"YES")))
+ }
+ else if(!xmlStrcmp(lcur->name, (const xmlChar *)"IP"))
{
- useRegex = 1;
+ int useRegex = 0;
+ xmlAttr *attrs = lcur->properties;
+ while(attrs)
+ {
+ if(!xmlStrcmp(attrs->name, (const xmlChar *)"isRegex"))
+ {
+ if(attrs->children && attrs->children->content &&
+ (!xmlStrcmp(attrs->children->content,
+ (const xmlChar *)"YES")))
+ {
+ useRegex = 1;
+ }
+ }
+ attrs = attrs->next;
+ }
+ vh->addIP((char*)lcur->children->content, useRegex);
}
- }
- attrs = attrs->next;
- }
- vh->addIP((char*)lcur->children->content, useRegex);
- }
- else if(!xmlStrcmp(lcur->name, (const xmlChar *)"PORT"))
- {
- int val = atoi((char*)lcur->children->content);
- if(val > (1 << 16) || strlen((const char*)lcur->children->content) > 6)
- {
- errMsg.assign("Error: specified port greater than 65536 or invalid:
");
- errMsg.append((char*)lcur->children->content);
- Server::getInstance()->logLockAccess();
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(errMsg.c_str());
- Server::getInstance()->logEndPrintError();
- Server::getInstance()->logUnlockAccess();
+ else if(!xmlStrcmp(lcur->name, (const xmlChar *)"PORT"))
+ {
+ int val = atoi((char*)lcur->children->content);
+ if(val > (1 << 16) || strlen((const
char*)lcur->children->content) > 6)
+ {
+ errMsg.assign("Error: specified port greater than 65536 or
invalid: ");
+ errMsg.append((char*)lcur->children->content);
+ Server::getInstance()->logWriteln(errMsg.c_str(), ERROR);
+ }
+ vh->setPort((u_short)val);
+ }
+ else if(!xmlStrcmp(lcur->name, (const xmlChar *)"PROTOCOL"))
+ {
+ char* lastChar = (char*)lcur->children->content;
+ while(*lastChar != '\0')
+ {
+ *lastChar = tolower (*lastChar);
+ lastChar++;
+ }
+ vh->setProtocolName((char*)lcur->children->content);
+ }
+ else if(!xmlStrcmp(lcur->name, (const xmlChar *)"DOCROOT"))
+ {
+ if(lcur->children && lcur->children->content)
+ {
+ char* lastChar = (char*)lcur->children->content;
+ while(*(lastChar+1) != '\0')
+ lastChar++;
- }
- vh->setPort((u_short)val);
- }
- else if(!xmlStrcmp(lcur->name, (const xmlChar *)"PROTOCOL"))
- {
- char* lastChar = (char*)lcur->children->content;
- while(*lastChar != '\0')
- {
- *lastChar = tolower (*lastChar);
- lastChar++;
- }
- vh->setProtocolName((char*)lcur->children->content);
- }
- else if(!xmlStrcmp(lcur->name, (const xmlChar *)"DOCROOT"))
- {
- if(lcur->children && lcur->children->content)
- {
- char* lastChar = (char*)lcur->children->content;
- while(*(lastChar+1) != '\0')
- lastChar++;
+ if(*lastChar == '\\' || *lastChar == '/')
+ {
+ *lastChar = '\0';
+ }
+ vh->setDocumentRoot((const char*)lcur->children->content);
+ }
+ else
+ {
+ vh->setDocumentRoot("");
+ }
+ }
+ else if(!xmlStrcmp(lcur->name, (const xmlChar *)"SYSFOLDER"))
+ {
+ if(lcur->children && lcur->children->content)
+ {
+ char* lastChar = (char*)lcur->children->content;
+ while(*(lastChar+1) != '\0')
+ lastChar++;
- if(*lastChar == '\\' || *lastChar == '/')
- {
- *lastChar = '\0';
- }
- vh->setDocumentRoot((const char*)lcur->children->content);
- }
- else
+ if(*lastChar == '\\' || *lastChar == '/')
+ {
+ *lastChar = '\0';
+ }
+ vh->setSystemRoot((const char*)lcur->children->content);
+ }
+ else
+ {
+ vh->setSystemRoot("");
+ }
+ }
+ else if(!xmlStrcmp(lcur->name, (const xmlChar *)"ACCESSLOG"))
+ {
+ loadXMLlogData ("ACCESSLOG", vh, lcur);
+ }
+ else if(!xmlStrcmp(lcur->name, (const xmlChar *)"WARNINGLOG"))
+ {
+ loadXMLlogData ("WARNINGLOG", vh, lcur);
+ }
+ else if(!xmlStrcmp(lcur->name, (const xmlChar *)"MIME_FILE"))
+ {
+ if(lcur->children)
+ vh->getMIME()->loadXML((char*)lcur->children->content);
+ }
+ else if(!xmlStrcmp(lcur->name, (const xmlChar *)"THROTTLING_RATE"))
+ {
+
vh->setThrottlingRate((u_long)atoi((char*)lcur->children->content));
+ }
+ else if(lcur->children && lcur->children->content)
+ {
+ string *old;
+ string *s = new string((const char*)lcur->children->content);
+ if(s == 0)
+ {
+ parser.close();
+ clean();
+ return -1;
+ }
+ string keyValue((const char*)lcur->name);
+ old = vh->hashedData.put(keyValue, s);
+ if(old)
+ {
+ delete old;
+ }
+ }
+ lcur = lcur->next;
+ }//while(lcur)
+
+ if (vh->openLogFiles ())
{
- vh->setDocumentRoot("");
+ errMsg.assign ("Error: opening log files");
+ Server::getInstance ()->logWriteln (errMsg.c_str (), ERROR);
+ delete vh;
+ vh = 0;
+ continue;
}
- }
- else if(!xmlStrcmp(lcur->name, (const xmlChar *)"SYSFOLDER"))
- {
- if(lcur->children && lcur->children->content)
- {
- char* lastChar = (char*)lcur->children->content;
- while(*(lastChar+1) != '\0')
- lastChar++;
- if(*lastChar == '\\' || *lastChar == '/')
- {
- *lastChar = '\0';
- }
- vh->setSystemRoot((const char*)lcur->children->content);
- }
- else
+ if ( vh->initializeSSL() < 0 )
{
- vh->setSystemRoot("");
+ errMsg.assign("Error: initializing vhost");
+ Server::getInstance()->logWriteln(errMsg.c_str(), ERROR);
+ delete vh;
+ vh = 0;
+ continue;
}
- }
- else if(!xmlStrcmp(lcur->name, (const xmlChar *)"ACCESSLOG"))
- {
- xmlAttr *attr;
- string opt;
- opt.assign("");
- vh->setAccessLogOpt("");
- if(lcur->children && lcur->children->content)
- vh->setAccessesLogFileName((char*)lcur->children->content);
- else
- {
- errMsg.assign("Error: invalid accesses log file name");
- Server::getInstance()->logLockAccess();
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(errMsg.c_str());
- Server::getInstance()->logEndPrintError();
- Server::getInstance()->logUnlockAccess();
- }
- attr = lcur->properties;
- while(attr)
+ if(addVHost(vh))
{
- opt.append((char*)attr->name);
- opt.append("=");
- opt.append((char*)attr->children->content);
-
- if(attr->next)
- {
- opt.append(",");
- }
- attr = attr->next;
+ errMsg.assign("Error: adding vhost");
+ Server::getInstance()->logWriteln(errMsg.c_str(), ERROR);
+ delete vh;
+ vh = 0;
+ continue;
}
- vh->setAccessLogOpt(opt.c_str());
- }
- else if(!xmlStrcmp(lcur->name, (const xmlChar *)"WARNINGLOG"))
- {
- xmlAttr *attr;
- string opt;
- opt.assign("");
-
- if(lcur->children && lcur->children->content)
- vh->setWarningsLogFileName((char*)lcur->children->content);
- else
- {
- errMsg.assign("Error: invalid warnings log file name");
- Server::getInstance()->logLockAccess();
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(errMsg.c_str());
- Server::getInstance()->logEndPrintError();
- Server::getInstance()->logUnlockAccess();
- }
- vh->setWarningLogOpt("");
- attr = lcur->properties;
- while(attr)
- {
- opt.append((char*)attr->name);
- opt.append("=");
- opt.append((char*)attr->children->content);
- if(attr->next)
- {
-
- opt.append(",");
- }
-
- attr=attr->next;
- }
-
- vh->setWarningLogOpt(opt.c_str());
- }
- else if(!xmlStrcmp(lcur->name, (const xmlChar *)"MIME_FILE"))
- {
- if(lcur->children)
- vh->getMIME()->loadXML((char*)lcur->children->content);
- }
- else if(!xmlStrcmp(lcur->name, (const xmlChar *)"THROTTLING_RATE"))
- {
- vh->setThrottlingRate((u_long)atoi((char*)lcur->children->content));
- }
- else if(lcur->children && lcur->children->content)
- {
- string *old;
- string *s = new string((const char*)lcur->children->content);
- if(s == 0)
- {
- parser.close();
- clean();
- return -1;
- }
- string keyValue((const char*)lcur->name);
- old = vh->hashedData.put(keyValue, s);
- if(old)
- {
- delete old;
- }
- }
- lcur = lcur->next;
- }//while(lcur)
-
- if(vh->openLogFiles())
- {
- errMsg.assign("Error: opening log files");
- Server::getInstance()->logLockAccess();
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(errMsg.c_str());
- Server::getInstance()->logEndPrintError();
- Server::getInstance()->logUnlockAccess();
-
- delete vh;
- vh =0;
- continue;
}
-
- if ( vh->initializeSSL() < 0 )
- {
- errMsg.assign("Error: initializing vhost");
- Server::getInstance()->logLockAccess();
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(errMsg.c_str());
- Server::getInstance()->logEndPrintError();
- Server::getInstance()->logUnlockAccess();
-
- delete vh;
- vh = 0;
- continue;
- }
-
- if(addVHost(vh))
- {
- errMsg.assign("Error: adding vhost");
- Server::getInstance()->logLockAccess();
- Server::getInstance()->logPreparePrintError();
- Server::getInstance()->logWriteln(errMsg.c_str());
- Server::getInstance()->logEndPrintError();
- Server::getInstance()->logUnlockAccess();
-
- delete vh;
- vh = 0;
- continue;
- }
-
- }
parser.close();
- changeFilesOwner();
+ changeLocationsOwner ();
return 0;
}
@@ -632,127 +637,131 @@
mutex.lock();
if(extSource)
- {
- int ret = extSource->save();
- mutex.unlock();
- return ret;
- }
+ {
+ int ret = extSource->save();
+ mutex.unlock();
+ return ret;
+ }
out.openFile(filename, File::MYSERVER_CREATE_ALWAYS |
File::MYSERVER_OPEN_WRITE);
out.writeToFile("<?xml version=\"1.0\"?>\r\n<VHOSTS>\r\n", 33, &nbw);
try
- {
- list<Vhost*>::iterator i = hostList.begin();
- for( ; i != hostList.end() ; i++)
{
- char port[6];
- list<Vhost::StringRegex*>::iterator il = (*i)->getIpList()->begin();
- list<Vhost::StringRegex*>::iterator hl = (*i)->getHostList()->begin();
- out.writeToFile("<VHOST>\r\n",9,&nbw);
+ list<Vhost*>::iterator i = hostList.begin();
+ for( ; i != hostList.end() ; i++)
+ {
+ char port[6];
+ list<Vhost::StringRegex*>::iterator il = (*i)->getIpList()->begin();
+ list<Vhost::StringRegex*>::iterator hl =
(*i)->getHostList()->begin();
+ out.writeToFile("<VHOST>\r\n",9,&nbw);
- out.writeToFile("<NAME>",6,&nbw);
- out.writeToFile((*i)->getName(), strlen((*i)->getName()), &nbw);
- out.writeToFile("</NAME>\r\n",9,&nbw);
+ out.writeToFile("<NAME>",6,&nbw);
+ out.writeToFile((*i)->getName(), strlen((*i)->getName()), &nbw);
+ out.writeToFile("</NAME>\r\n",9,&nbw);
- for(; il != (*i)->getIpList()->end(); il++)
- {
- string *n = &((*il)->name);
- out.writeToFile("<IP>",4,&nbw);
- out.writeToFile(n->c_str(), n->length(), &nbw);
- out.writeToFile("</IP>\r\n",7,&nbw);
- }
+ for(; il != (*i)->getIpList()->end(); il++)
+ {
+ string *n = &((*il)->name);
+ out.writeToFile("<IP>",4,&nbw);
+ out.writeToFile(n->c_str(), n->length(), &nbw);
+ out.writeToFile("</IP>\r\n",7,&nbw);
+ }
- for(; hl != (*i)->getHostList()->end(); hl++)
- {
- string *n = &((*hl)->name);
- out.writeToFile("<HOST>",6,&nbw);
- out.writeToFile(n->c_str(), n->length(), &nbw);
- out.writeToFile("</HOST>\r\n",9,&nbw);
- }
+ for(; hl != (*i)->getHostList()->end(); hl++)
+ {
+ string *n = &((*hl)->name);
+ out.writeToFile("<HOST>",6,&nbw);
+ out.writeToFile(n->c_str(), n->length(), &nbw);
+ out.writeToFile("</HOST>\r\n",9,&nbw);
+ }
- out.writeToFile("<PORT>",6,&nbw);
- sprintf(port,"%i", (*i)->getPort());
- out.writeToFile(port,(u_long)strlen(port),&nbw);
- out.writeToFile("</PORT>\r\n",9,&nbw);
+ out.writeToFile("<PORT>",6,&nbw);
+ sprintf(port,"%i", (*i)->getPort());
+ out.writeToFile(port,(u_long)strlen(port),&nbw);
+ out.writeToFile("</PORT>\r\n",9,&nbw);
- if((*i)->getVhostSSLContext()->getPrivateKeyFile().length())
- {
- string &pk = (*i)->getVhostSSLContext()->getPrivateKeyFile();
- out.writeToFile("<SSL_PRIVATEKEY>",16,&nbw);
- out.writeToFile(pk.c_str(), pk.length(),&nbw);
- out.writeToFile("</SSL_PRIVATEKEY>\r\n",19,&nbw);
- }
+ if((*i)->getVhostSSLContext()->getPrivateKeyFile().length())
+ {
+ string &pk = (*i)->getVhostSSLContext()->getPrivateKeyFile();
+ out.writeToFile("<SSL_PRIVATEKEY>",16,&nbw);
+ out.writeToFile(pk.c_str(), pk.length(),&nbw);
+ out.writeToFile("</SSL_PRIVATEKEY>\r\n",19,&nbw);
+ }
- if((*i)->getVhostSSLContext()->getCertificateFile().length())
- {
- string &certificate = (*i)->getVhostSSLContext()->getCertificateFile();
- out.writeToFile("<SSL_CERTIFICATE>", 17, &nbw);
- out.writeToFile(certificate.c_str(), (u_long)certificate.length(),
- &nbw);
- out.writeToFile("</SSL_CERTIFICATE>\r\n", 20, &nbw);
- }
+ if((*i)->getVhostSSLContext()->getCertificateFile().length())
+ {
+ string &certificate =
(*i)->getVhostSSLContext()->getCertificateFile();
+ out.writeToFile("<SSL_CERTIFICATE>", 17, &nbw);
+ out.writeToFile(certificate.c_str(),
(u_long)certificate.length(),
+ &nbw);
+ out.writeToFile("</SSL_CERTIFICATE>\r\n", 20, &nbw);
+ }
- if((*i)->getVhostSSLContext()->getPassword().length())
- {
- string& pw = (*i)->getVhostSSLContext()->getPassword();
- out.writeToFile("<SSL_PASSWORD>", 14, &nbw);
- out.writeToFile(pw.c_str(), pw.length(), &nbw);
- out.writeToFile("</SSL_PASSWORD>\r\n", 17, &nbw);
- }
+ if((*i)->getVhostSSLContext()->getPassword().length())
+ {
+ string& pw = (*i)->getVhostSSLContext()->getPassword();
+ out.writeToFile("<SSL_PASSWORD>", 14, &nbw);
+ out.writeToFile(pw.c_str(), pw.length(), &nbw);
+ out.writeToFile("</SSL_PASSWORD>\r\n", 17, &nbw);
+ }
- out.writeToFile("<PROTOCOL>", 10, &nbw);
- out.writeToFile((*i)->getProtocolName(),
- strlen((*i)->getProtocolName()), &nbw);
+ out.writeToFile("<PROTOCOL>", 10, &nbw);
+ out.writeToFile((*i)->getProtocolName(),
+ strlen((*i)->getProtocolName()), &nbw);
- out.writeToFile("</PROTOCOL>\r\n", 13, &nbw);
+ out.writeToFile("</PROTOCOL>\r\n", 13, &nbw);
- out.writeToFile("<DOCROOT>", 9, &nbw);
- out.writeToFile((*i)->getDocumentRoot().c_str(),
- (*i)->getDocumentRoot().length(), &nbw);
- out.writeToFile("</DOCROOT>\r\n", 12, &nbw);
+ out.writeToFile("<DOCROOT>", 9, &nbw);
+ out.writeToFile((*i)->getDocumentRoot().c_str(),
+ (*i)->getDocumentRoot().length(), &nbw);
+ out.writeToFile("</DOCROOT>\r\n", 12, &nbw);
- out.writeToFile("<SYSFOLDER>", 11, &nbw);
- out.writeToFile((*i)->getSystemRoot().c_str(),
- (*i)->getSystemRoot().length(), &nbw);
+ out.writeToFile("<SYSFOLDER>", 11, &nbw);
+ out.writeToFile((*i)->getSystemRoot().c_str(),
+ (*i)->getSystemRoot().length(), &nbw);
- out.writeToFile("</SYSFOLDER>\r\n", 14, &nbw);
+ out.writeToFile("</SYSFOLDER>\r\n", 14, &nbw);
- out.writeToFile("<ACCESSLOG>", 13, &nbw);
- out.writeToFile((*i)->getAccessesLogFileName(),
- (u_long)strlen((*i)->getAccessesLogFileName()), &nbw);
- out.writeToFile("</ACCESSLOG>\r\n", 16, &nbw);
+ out.writeToFile("<ACCESSLOG>", 13, &nbw);
+
+ string accessData = saveXMLlogData ("ACCESSLOG", *i);
+ string warningData = saveXMLlogData ("WARNINGLOG", *i);
+
+ out.writeToFile (accessData.c_str (), accessData.size (), &nbw);
+
+ out.writeToFile("</ACCESSLOG>\r\n", 16, &nbw);
- out.writeToFile("<WARNINGLOG>", 12, &nbw);
- out.writeToFile((*i)->getWarningsLogFileName(),
- (u_long)strlen((*i)->getWarningsLogFileName()),&nbw);
- out.writeToFile("</WARNINGLOG>\r\n", 15, &nbw);
+ out.writeToFile("<WARNINGLOG>", 12, &nbw);
+
+ out.writeToFile (warningData.c_str (), warningData.size (), &nbw);
+
+ out.writeToFile("</WARNINGLOG>\r\n", 15, &nbw);
- {
- HashMap<string, string*>::Iterator it = (*i)->hashedData.begin();
- for(; it != (*i)->hashedData.end(); it++)
- {
- ostringstream outString;
- outString << "<" << it.getKey() << ">" << (*it) << "</"
- << it.getKey() << ">" << endl;
- out.writeToFile(outString.str().c_str(),outString.str().size(),&nbw);
+ {
+ HashMap<string, string*>::Iterator it = (*i)->hashedData.begin();
+ for(; it != (*i)->hashedData.end(); it++)
+ {
+ ostringstream outString;
+ outString << "<" << it.getKey() << ">" << (*it) << "</"
+ << it.getKey() << ">" << endl;
+
out.writeToFile(outString.str().c_str(),outString.str().size(),&nbw);
+ }
+ out.writeToFile("</VHOST>\r\n", 10, &nbw);
+ }
}
- out.writeToFile("</VHOST>\r\n", 10, &nbw);
- }
+ out.writeToFile("</VHOSTS>\r\n", 11, &nbw);
+ out.close();
+ mutex.unlock();
}
- out.writeToFile("</VHOSTS>\r\n", 11, &nbw);
- out.close();
- mutex.unlock();
- }
catch(...)
- {
- mutex.unlock();
- };
+ {
+ mutex.unlock();
+ };
return 0;
}
-
/*!
*Get a virtual host by its position in the list.
*Zero based list.
@@ -763,33 +772,33 @@
Vhost* ret = 0;
mutex.lock();
try
- {
- list<Vhost*>::iterator i = hostList.begin();
- if(extSource)
{
- ret=extSource->getVHostByNumber(n);
+ list<Vhost*>::iterator i = hostList.begin();
+ if(extSource)
+ {
+ ret=extSource->getVHostByNumber(n);
+ mutex.unlock();
+ return ret;
+ }
+
+ for( ; i != hostList.end(); i++)
+ {
+ if(!(n--))
+ {
+ ret = *i;
+ ret->addRef();
+ break;
+ }
+ }
mutex.unlock();
+
return ret;
}
-
- for( ; i != hostList.end(); i++)
+ catch(...)
{
- if(!(n--))
- {
- ret = *i;
- ret->addRef();
- break;
- }
- }
- mutex.unlock();
-
- return ret;
- }
- catch(...)
- {
- mutex.unlock();
- return ret;
- };
+ mutex.unlock();
+ return ret;
+ };
}
/*!
@@ -801,26 +810,26 @@
{
mutex.lock();
try
- {
- list<Vhost*>::iterator i = hostList.begin();
+ {
+ list<Vhost*>::iterator i = hostList.begin();
- for( ;i != hostList.end(); i++)
- {
- if(!(n--))
- {
- delete *i;
- mutex.unlock();
- return 1;
- }
+ for( ;i != hostList.end(); i++)
+ {
+ if(!(n--))
+ {
+ delete *i;
+ mutex.unlock();
+ return 1;
+ }
+ }
+ mutex.unlock();
+ return 0;
}
- mutex.unlock();
- return 0;
- }
catch(...)
- {
- mutex.unlock();
- return 0;
- };
+ {
+ mutex.unlock();
+ return 0;
+ };
}
/*!
Modified: trunk/myserver/src/connections_scheduler/connections_scheduler.cpp
===================================================================
--- trunk/myserver/src/connections_scheduler/connections_scheduler.cpp
2008-10-08 19:28:07 UTC (rev 2873)
+++ trunk/myserver/src/connections_scheduler/connections_scheduler.cpp
2008-10-08 22:21:10 UTC (rev 2874)
@@ -357,11 +357,7 @@
{
if(server)
{
- server->logLockAccess();
- server->logPreparePrintError();
- server->logWriteln("Error initializing socket pair.");
- server->logEndPrintError();
- server->logUnlockAccess();
+ server->logWriteln("Error initializing socket pair.", ERROR);
}
return;
}
@@ -375,11 +371,7 @@
{
if(server)
{
- server->logLockAccess();
- server->logPreparePrintError();
- server->logWriteln("Error initializing dispatcher thread.");
- server->logEndPrintError();
- server->logUnlockAccess();
+ server->logWriteln("Error initializing dispatcher thread.", ERROR);
}
dispatchedThreadId = 0;
}
Modified: trunk/myserver/src/connections_scheduler/listen_threads.cpp
===================================================================
--- trunk/myserver/src/connections_scheduler/listen_threads.cpp 2008-10-08
19:28:07 UTC (rev 2873)
+++ trunk/myserver/src/connections_scheduler/listen_threads.cpp 2008-10-08
22:21:10 UTC (rev 2874)
@@ -96,9 +96,7 @@
serverSocketIPv4->socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (serverSocketIPv4->getHandle() == (FileHandle)INVALID_SOCKET)
{
- server->logPreparePrintError();
- server->logWriteln(languageParser->getValue("ERR_OPENP"));
- server->logEndPrintError();
+ server->logWriteln(languageParser->getValue("ERR_OPENP"), ERROR);
delete serverSocketIPv4;
serverSocketIPv4 = NULL;
}
@@ -122,9 +120,7 @@
(const char *)&optvalReuseAddr,
sizeof(optvalReuseAddr)) < 0)
{
- server->logPreparePrintError();
- server->logWriteln(languageParser->getValue("ERR_ERROR"));
- server->logEndPrintError();
+ server->logWriteln(languageParser->getValue("ERR_ERROR"), ERROR);
delete serverSocketIPv4;
serverSocketIPv4 = NULL;
//return 0; allow IPv6
@@ -140,9 +136,7 @@
if (serverSocketIPv4->bind(&sockServerSocketIPv4,
sizeof(sockaddr_in)) != 0)
{
- server->logPreparePrintError();
- server->logWriteln(languageParser->getValue("ERR_BIND"));
- server->logEndPrintError();
+ server->logWriteln(languageParser->getValue("ERR_BIND"), ERROR);
delete serverSocketIPv4;
serverSocketIPv4 = NULL;
}
@@ -161,9 +155,7 @@
serverSocketIPv6->socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
if ( serverSocketIPv6->getHandle() == (FileHandle)INVALID_SOCKET )
{
- server->logPreparePrintError();
- server->logWriteln(languageParser->getValue("ERR_OPENP"));
- server->logEndPrintError();
+ server->logWriteln(languageParser->getValue("ERR_OPENP"), ERROR);
delete serverSocketIPv6;
serverSocketIPv6 = NULL;
}
@@ -185,9 +177,7 @@
(const char *)&optvalReuseAddr,
sizeof(optvalReuseAddr))<0)
{
- server->logPreparePrintError();
- server->logWriteln(languageParser->getValue("ERR_ERROR"));
- server->logEndPrintError();
+ server->logWriteln(languageParser->getValue("ERR_ERROR"), ERROR);
delete serverSocketIPv6;
serverSocketIPv6 = NULL;
//return 0;allow IPv6
@@ -197,9 +187,7 @@
(const char *)&optvalReuseAddr,
sizeof(optvalReuseAddr)) < 0)
{
- server->logPreparePrintError();
- server->logWriteln(languageParser->getValue("ERR_ERROR"));
- server->logEndPrintError();
+ server->logWriteln(languageParser->getValue("ERR_ERROR"), ERROR);
delete serverSocketIPv6;
serverSocketIPv6 = NULL;
//return 0;allow IPv6
@@ -215,9 +203,7 @@
if ( serverSocketIPv6->bind(&sockServerSocketIPv6,
sizeof(sockaddr_in6)) != 0)
{
- server->logPreparePrintError();
- server->logWriteln(languageParser->getValue("ERR_BIND"));
- server->logEndPrintError();
+ server->logWriteln(languageParser->getValue("ERR_BIND"), ERROR);
delete serverSocketIPv6;
serverSocketIPv6 = NULL;
}
@@ -241,18 +227,14 @@
server->logWriteln(languageParser->getValue("MSG_SLISTEN"));
if (serverSocketIPv4 != NULL && serverSocketIPv4->listen(SOMAXCONN))
{
- server->logPreparePrintError();
- server->logWriteln(languageParser->getValue("ERR_LISTEN"));
- server->logEndPrintError();
+ server->logWriteln(languageParser->getValue("ERR_LISTEN"), ERROR);
delete serverSocketIPv4;
serverSocketIPv4 = NULL;
}
if (serverSocketIPv6 != NULL && serverSocketIPv6->listen(SOMAXCONN))
{
- server->logPreparePrintError();
- server->logWriteln(languageParser->getValue("ERR_LISTEN"));
- server->logEndPrintError();
+ server->logWriteln(languageParser->getValue("ERR_LISTEN"), ERROR);
delete serverSocketIPv6;
serverSocketIPv6 = NULL;
}
Modified: trunk/myserver/src/filter/console.cpp
===================================================================
--- trunk/myserver/src/filter/console.cpp 2008-10-08 19:28:07 UTC (rev
2873)
+++ trunk/myserver/src/filter/console.cpp 2008-10-08 22:21:10 UTC (rev
2874)
@@ -1,25 +1,24 @@
/*
-MyServer
-Copyright (C) 2006, 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.
+ MyServer
+ Copyright (C) 2006, 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.
+ 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/>.
+ 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/filter/console.h>
Console::Console () : Stream ()
{
-
}
Console::~Console ()
@@ -30,19 +29,84 @@
int
Console::flush (u_long* nbw)
{
- return *nbw = 0;
+ if (fd)
+ {
+ return *nbw = 0;
+ }
+ return 1;
}
int
Console::read (char* buffer, u_long len, u_long* nbr)
{
- return *nbr = 0;
+ if (fd)
+ {
+ return *nbr = 0;
+ }
+ return 1;
}
int
Console::write (const char* buffer, u_long len, u_long* nbw)
{
- cout << buffer;
- *nbw = len;
+ if (fd)
+ {
+ *fd << buffer;
+ *nbw = len;
+ return 0;
+ }
+ return 1;
+}
+
+int
+Console::openConsole (string fd)
+{
+ int success = 1;
+ if (!fd.compare ("stdout"))
+ {
+ this->fd = &cout;
+ success = 0;
+ }
+ else if (!fd.compare ("stderr"))
+ {
+ this->fd = &cerr;
+ success = 0;
+ }
+ return success;
+}
+
+int
+Console::enterErrorMode ()
+{
+#ifdef WIN32
+
+ int success =
+ SetConsoleTextAttribute (GetStdHandle ((fd == &cout) ? STD_OUTPUT_HANDLE :
STD_ERROR_HANDLE),
+ FOREGROUND_RED |
+ FOREGROUND_INTENSITY);
+ if (success)
+ return 0;
+#endif
+#ifdef NOT_WIN
+ *fd << "\033[31;1m";
return 0;
+#endif
}
+
+int
+Console::exitErrorMode ()
+{
+#ifdef WIN32
+ int success =
+ SetConsoleTextAttribute (GetStdHandle ((fd == &cout) ? STD_OUTPUT_HANDLE :
STD_ERROR_HANDLE),
+ FOREGROUND_RED |
+ FOREGROUND_GREEN |
+ FOREGROUND_BLUE);
+ if (success)
+ return 0;
+#endif
+#ifdef NOT_WIN
+ *fd << "\033[0m";
+ return 0;
+#endif
+}
Modified: trunk/myserver/src/http_handler/cgi/cgi.cpp
===================================================================
--- trunk/myserver/src/http_handler/cgi/cgi.cpp 2008-10-08 19:28:07 UTC (rev
2873)
+++ trunk/myserver/src/http_handler/cgi/cgi.cpp 2008-10-08 22:21:10 UTC (rev
2874)
@@ -195,7 +195,6 @@
{
if(!FilesUtility::fileExists(tmpCgiPath.c_str()))
{
- td->connection->host->warningsLogRequestAccess(td->id);
if(tmpCgiPath.length() > 0)
{
string msg;
@@ -209,7 +208,6 @@
td->connection->host->warningsLogWrite(
"Cgi: Executable file not specified");
}
- td->connection->host->warningsLogTerminateAccess(td->id);
td->scriptPath.assign("");
td->scriptFile.assign("");
td->scriptDir.assign("");
@@ -253,10 +251,8 @@
*/
if(stdOutFile.create())
{
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite
("Cgi: Cannot create CGI stdout file");
- td->connection->host->warningsLogTerminateAccess(td->id);
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
}
@@ -265,9 +261,7 @@
if(stdInFile.openFile(td->inputDataPath,
File::MYSERVER_OPEN_READ | File::MYSERVER_OPEN_ALWAYS))
{
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite("Cgi: Cannot open CGI stdin file");
- td->connection->host->warningsLogTerminateAccess(td->id);
stdOutFile.close();
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
@@ -298,9 +292,7 @@
spi.stdIn == (FileHandle)-1 ||
spi.stdOut == (FileHandle)-1)
{
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite("Cgi: Invalid
base/file/file.handler");
- td->connection->host->warningsLogTerminateAccess(td->id);
stdOutFile.close();
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
@@ -312,10 +304,8 @@
{
stdInFile.close();
stdOutFile.close();
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite
("Cgi: Error in the CGI execution");
- td->connection->host->warningsLogTerminateAccess(td->id);
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
}
@@ -352,10 +342,8 @@
{
stdInFile.close();
stdOutFile.close();
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite
("Cgi: Error reading from CGI std out file");
- td->connection->host->warningsLogTerminateAccess(td->id);
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
}
@@ -380,9 +368,7 @@
if(headerOffset == 0)
{
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite("Cgi: Error CGI zero bytes read");
- td->connection->host->warningsLogTerminateAccess(td->id);
td->http->raiseHTTPError(500);
stdOutFile.close();
stdInFile.close();
@@ -489,9 +475,7 @@
&nbw,
1))
{
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite("Cgi: Error loading filters");
- td->connection->host->warningsLogTerminateAccess(td->id);
stdOutFile.close();
stdInFile.close();
cgiProc.terminateProcess();
Modified: trunk/myserver/src/http_handler/fastcgi/fastcgi.cpp
===================================================================
--- trunk/myserver/src/http_handler/fastcgi/fastcgi.cpp 2008-10-08 19:28:07 UTC
(rev 2873)
+++ trunk/myserver/src/http_handler/fastcgi/fastcgi.cpp 2008-10-08 22:21:10 UTC
(rev 2874)
@@ -114,10 +114,8 @@
&nbw,
1))
{
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(
"FastCGI: Error loading filters");
- td->connection->host->warningsLogTerminateAccess(td->id);
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
}
@@ -211,9 +209,7 @@
if(Server::getInstance()->getVerbosity() > 2)
{
*td->buffer << "FastCGI: Error to build env string" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
}
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
@@ -227,9 +223,7 @@
if(Server::getInstance()->getVerbosity() > 2)
{
*td->buffer << "FastCGI: Error opening stdin file" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
}
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
@@ -244,9 +238,7 @@
{
*td->buffer << "FastCGI: Error connecting to FastCGI "
<< cmdLine.str().c_str() << " process" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
}
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
@@ -264,9 +256,7 @@
if(Server::getInstance()->getVerbosity() > 2)
{
*td->buffer<< "FastCGI: Error beginning the request" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
}
chain.clearAllFilters();
con.sock.close();
@@ -280,9 +270,7 @@
if(Server::getInstance()->getVerbosity() > 2)
{
*td->buffer << "FastCGI: Error sending params" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
}
chain.clearAllFilters();
con.sock.close();
@@ -295,9 +283,7 @@
if(Server::getInstance()->getVerbosity() > 2)
{
*td->buffer << "FastCGI: Error sending params" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
}
chain.clearAllFilters();
con.sock.close();
@@ -313,9 +299,7 @@
if(Server::getInstance()->getVerbosity() > 2)
{
*td->buffer << "FastCGI: Error sending POST data" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
}
/*! Send the STDIN data. */
@@ -328,10 +312,8 @@
if(Server::getInstance()->getVerbosity() > 2)
{
*td->buffer << "FastCGI: Error reading from file" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(
td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
}
return td->http->sendHTTPhardError500();
}
@@ -352,9 +334,7 @@
if(Server::getInstance()->getVerbosity() > 2)
{
*td->buffer << "FastCGI: Error sending data" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
}
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
@@ -369,11 +349,9 @@
if(Server::getInstance()->getVerbosity() > 2)
{
*td->buffer << "FastCGI: Error sending POST data" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->
warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
}
con.sock.close();
return td->http->raiseHTTPError(500);
@@ -393,9 +371,7 @@
{
td->buffer->setLength(0);
*td->buffer << "FastCGI: Error opening stdout file" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
return td->http->raiseHTTPError(500);
}
@@ -420,9 +396,7 @@
{
td->buffer->setLength(0);
*td->buffer << "FastCGI: Error reading data" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
sendFcgiBody(&con, 0, 0, FCGIABORT_REQUEST, id);
ret = 0;
break;
@@ -432,9 +406,7 @@
{
td->buffer->setLength(0);
*td->buffer << "FastCGI: Error timeout" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
sendFcgiBody(&con, 0, 0, FCGIABORT_REQUEST, id);
con.sock.shutdown(2);
con.sock.close();
Modified: trunk/myserver/src/http_handler/http_dir/http_dir.cpp
===================================================================
--- trunk/myserver/src/http_handler/http_dir/http_dir.cpp 2008-10-08
19:28:07 UTC (rev 2873)
+++ trunk/myserver/src/http_handler/http_dir/http_dir.cpp 2008-10-08
22:21:10 UTC (rev 2874)
@@ -200,9 +200,7 @@
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);
}
Modified: trunk/myserver/src/http_handler/http_file/http_file.cpp
===================================================================
--- trunk/myserver/src/http_handler/http_file/http_file.cpp 2008-10-08
19:28:07 UTC (rev 2873)
+++ trunk/myserver/src/http_handler/http_file/http_file.cpp 2008-10-08
22:21:10 UTC (rev 2874)
@@ -509,9 +509,7 @@
{
file->close();
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);
}
@@ -519,9 +517,7 @@
{
file->close();
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);
};
Modified: trunk/myserver/src/http_handler/isapi/isapi.cpp
===================================================================
--- trunk/myserver/src/http_handler/isapi/isapi.cpp 2008-10-08 19:28:07 UTC
(rev 2873)
+++ trunk/myserver/src/http_handler/isapi/isapi.cpp 2008-10-08 22:21:10 UTC
(rev 2874)
@@ -1027,10 +1027,8 @@
/*!
*On other archs returns a non implemented error.
*/
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(
"ISAPI: Not implemented");
- td->connection->host->warningsLogTerminateAccess(td->id);
return td->http->raiseHTTPError(501);
#endif
}
Modified: trunk/myserver/src/http_handler/mscgi/mscgi.cpp
===================================================================
--- trunk/myserver/src/http_handler/mscgi/mscgi.cpp 2008-10-08 19:28:07 UTC
(rev 2873)
+++ trunk/myserver/src/http_handler/mscgi/mscgi.cpp 2008-10-08 22:21:10 UTC
(rev 2874)
@@ -107,9 +107,7 @@
&nbw,
1))
{
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite("MSCGI: Error loading filters");
- td->connection->host->warningsLogTerminateAccess(td->id);
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
}
@@ -133,9 +131,7 @@
string msg;
msg.assign("MSCGI: error accessing entrypoint for ");
msg.append(exec);
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(msg.c_str());
- td->connection->host->warningsLogTerminateAccess(td->id);
return td->http->raiseHTTPError(500);
}
hinstLib.close();
Modified: trunk/myserver/src/http_handler/scgi/scgi.cpp
===================================================================
--- trunk/myserver/src/http_handler/scgi/scgi.cpp 2008-10-08 19:28:07 UTC
(rev 2873)
+++ trunk/myserver/src/http_handler/scgi/scgi.cpp 2008-10-08 22:21:10 UTC
(rev 2874)
@@ -81,9 +81,7 @@
&nbw,
1))
{
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite("SCGI: Error loading filters");
- td->connection->host->warningsLogTerminateAccess(td->id);
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
}
@@ -177,9 +175,7 @@
if(Server::getInstance()->getVerbosity() > 2)
{
*td->buffer << "SCGI: Error to build env string" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
}
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
@@ -193,9 +189,7 @@
if(Server::getInstance()->getVerbosity() > 2)
{
*td->buffer << "SCGI: Error opening stdin file" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
}
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
@@ -210,9 +204,7 @@
{
*td->buffer << "SCGI: Error connecting to SCGI "
<< cmdLine.str().c_str() << " process" << '\0';
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
}
chain.clearAllFilters();
return td->http->raiseHTTPError(500);
Modified: trunk/myserver/src/http_handler/wincgi/wincgi.cpp
===================================================================
--- trunk/myserver/src/http_handler/wincgi/wincgi.cpp 2008-10-08 19:28:07 UTC
(rev 2873)
+++ trunk/myserver/src/http_handler/wincgi/wincgi.cpp 2008-10-08 22:21:10 UTC
(rev 2874)
@@ -476,9 +476,7 @@
*/
td->buffer->setLength(0);
*td->buffer << "WinCGI: Not implemented";
- td->connection->host->warningsLogRequestAccess(td->id);
td->connection->host->warningsLogWrite(td->buffer->getBuffer());
- td->connection->host->warningsLogTerminateAccess(td->id);
return td->http->raiseHTTPError(501);
#endif
}
Modified: trunk/myserver/src/log/log_manager.cpp
===================================================================
--- trunk/myserver/src/log/log_manager.cpp 2008-10-08 19:28:07 UTC (rev
2873)
+++ trunk/myserver/src/log/log_manager.cpp 2008-10-08 22:21:10 UTC (rev
2874)
@@ -17,15 +17,11 @@
#include <include/log/log_manager.h>
-int const LogManager::TYPE_CONSOLE = 1;
-int const LogManager::TYPE_FILE = 2;
-
-LogManager::LogManager (FiltersFactory* filtersFactory,
- LogStreamFactory* logStreamFactory,
+LogManager::LogManager (FiltersFactory* ff,
LoggingLevel level) : level (level)
{
- this->filtersFactory = filtersFactory;
- this->logStreamFactory = logStreamFactory;
+ this->ff = ff;
+ lsf = new LogStreamFactory ();
mutex = new Mutex ();
mutex->init ();
}
@@ -35,343 +31,460 @@
if (!empty ())
clear ();
delete mutex;
+ delete lsf;
}
int
-LogManager::addLogStream (string location,
- list<string>& filters,
- u_long cycleLog)
+LogManager::clear ()
{
mutex->lock ();
- int retVal = 1;
- if (!contains (location))
+ map<string, LogStream*>::iterator it;
+ for (it = logStreams.begin (); it != logStreams.end (); it++)
{
- LogStream* logStream = logStreamFactory->createLogStream (filtersFactory,
- location,
- filters,
- cycleLog);
- if (logStream)
- {
- logStreams[location] = logStream;
- retVal = 0;
- }
+ delete it->second;
}
+ logStreams.clear ();
+ owners.clear ();
mutex->unlock ();
- return retVal;
+ return !empty ();
}
int
-LogManager::removeLogStream (string location)
+LogManager::add (void* owner, string type, string location,
+ list<string>& filters, u_long cycle)
{
mutex->lock ();
- int retVal = 1;
- if (contains (location))
+ int success = 1;
+ if (!contains (location))
{
- delete logStreams[location];
- logStreams.erase (location);
- retVal = 0;
+ LogStream* ls = lsf->create (ff, location, filters, cycle);
+ if (ls)
+ {
+ success = (add (owner) || add (owner, type) ||
+ add (owner, type, location, ls));
+ }
}
mutex->unlock ();
- return retVal;
+ return success;
}
-LogStream*
-LogManager::getLogStream (string location)
+int
+LogManager::add (void* owner)
{
- LogStream* retVal = 0;
- if (contains (location))
- retVal = logStreams[location];
- return retVal;
+ int success = 1;
+ if (owner)
+ {
+ if (!contains (owner))
+ {
+ map<string, map<string, LogStream*> > type;
+ owners[owner] = type;
+ }
+ success = 0;
+ }
+ return success;
}
int
-LogManager::notifyLogStreams (LogStreamEvent evt,
- void* message,
- void* reply)
+LogManager::add (void* owner, string type)
{
- map<string, LogStream*>::iterator it;
- int retVal = 0;
- for (it = logStreams.begin (); it != logStreams.end (); it++)
+ int success = 1;
+ if (type.size ())
{
- retVal |= it->second->update (evt, message, reply);
+ if (!contains (owner, type))
+ {
+ map<string, LogStream*> target;
+ owners[owner][type] = target;
+ }
+ success = 0;
}
- return retVal;
+ return success;
}
int
-LogManager::log (string message, LoggingLevel level, string location)
+LogManager::add (void* owner, string type, string location, LogStream* ls)
{
+ logStreams[location] = ls;
+ owners[owner][type][location] = ls;
+ if (contains (location) && contains (owner, type, location))
+ {
+ return 0;
+ }
+ return 1;
+}
+
+int
+LogManager::remove (void* owner)
+{
mutex->lock ();
- int retVal = 1;
- if (level >= this->level)
+ int success = 1;
+ if (contains (owner))
{
- if (contains (location))
+ map<string, map<string, LogStream*> > m = owners[owner];
+ map<string, map<string, LogStream*> >::iterator it_1;
+ for (it_1 = m.begin (); it_1 != m.end (); it_1++)
{
- retVal = logStreams[location]->log (message);
+ map<string, LogStream*> t = it_1->second;
+ map<string, LogStream*>::iterator it_2;
+ for (it_2 = t.begin (); it_2 != t.end (); it_2++)
+ {
+ delete it_2->second;
+ logStreams.erase (it_2->first);
+ }
+ t.clear ();
}
- else if (!location.compare ("all"))
- {
- retVal = notifyLogStreams (EVT_LOG, static_cast<void*>(&message));
- }
+ m.clear ();
+ success = 0;
}
mutex->unlock ();
- return retVal;
+ return success;
}
int
-LogManager::close (string location)
+LogManager::notify (void* owner, string type, string location,
+ LogStreamEvent evt, void* message, void* reply)
{
- mutex->lock ();
- int retVal = 1;
- if (contains (location))
+ int success = 1;
+ if (contains (owner, type, location))
{
- retVal = logStreams[location]->close ();
+ success = owners[owner][type][location]->update (evt, message, reply);
}
- else if (!location.compare ("all"))
+ return success;
+}
+
+int
+LogManager::notify (void* owner, string type, LogStreamEvent evt,
+ void* message, void* reply)
+{
+ int success = 1;
+ if (contains (owner, type))
{
- retVal = notifyLogStreams (EVT_CLOSE);
+ success = 0;
+ map<string, LogStream*> m = owners[owner][type];
+ map<string, LogStream*>::iterator it;
+ for (it = m.begin (); it != m.end (); it++)
+ {
+ success |= notify (owner, type, it->first, evt, message, reply);
+ }
}
- mutex->unlock ();
- return retVal;
+ return success;
}
-void
-LogManager::setCycleLog (u_long cycleLog, string location)
+int
+LogManager::notify (void* owner, LogStreamEvent evt, void* message,
+ void* reply)
{
- mutex->lock ();
- if (contains (location))
+ int success = 1;
+ if (contains (owner))
{
- logStreams[location]->setCycleLog (cycleLog);
+ success = 0;
+ map<string, map<string, LogStream*> > m = owners[owner];
+ map<string, map<string, LogStream*> >::iterator it;
+ for (it = m.begin (); it != m.end (); it++)
+ {
+ success |= notify (owner, it->first, evt, message, reply);
+ }
}
- else if (!location.compare ("all"))
- {
- notifyLogStreams (EVT_SET_CYCLE_LOG, static_cast<void*>(&cycleLog));
- }
- mutex->unlock ();
+ return success;
}
-LoggingLevel
-LogManager::setLoggingLevel (LoggingLevel level)
+int
@@ Diff output truncated at 153600 characters. @@
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [myserver-commit] [2874] Use the new LogManager interface in its dependent classes.,
Francesco Pipita <=