myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. 6004dab381


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 6004dab381a466346cc246592cde4be0cf800dfb
Date: Wed, 12 Aug 2009 18:01:57 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  6004dab381a466346cc246592cde4be0cf800dfb (commit)
      from  1e035ef322a4158bc570092a5d0d513c09163a55 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit 6004dab381a466346cc246592cde4be0cf800dfb
Author: Giuseppe Scrivano <address@hidden>
Date:   Wed Aug 12 19:59:57 2009 +0200

    LogManager uses arguments by reference and not by copy for logging.

diff --git a/myserver/include/conf/vhost/vhost.h 
b/myserver/include/conf/vhost/vhost.h
index 8540c08..b841fc5 100644
--- a/myserver/include/conf/vhost/vhost.h
+++ b/myserver/include/conf/vhost/vhost.h
@@ -206,7 +206,11 @@ public:
   void setProtocolData(VhostProtocolData* data){protocolData = data;}
 
   MimeRecord* getLocationMime (string& loc){return locationsMime.get (loc);}
+
 private:
+  const static string accessLogType;
+  const static string warningLogType;
+
   VhostProtocolData*  protocolData;
 
   list<NodeTree<string>*> hashedDataTrees;
diff --git a/myserver/include/log/log_manager.h 
b/myserver/include/log/log_manager.h
index e01064d..22327e0 100644
--- a/myserver/include/log/log_manager.h
+++ b/myserver/include/log/log_manager.h
@@ -37,32 +37,34 @@ class LogManager
 public:
   LogManager (FiltersFactory* ff, LoggingLevel level = MYSERVER_LOG_MSG_INFO);
   ~LogManager ();
-  int add (void* owner, string type, string location,
+  int add (const 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 = MYSERVER_LOG_MSG_INFO);
-  int log (void* owner, string type, string message, bool appendNL = false,
+  int remove (const void *owner);
+
+  int log (const void* owner, string & message, bool appendNL = false,
            LoggingLevel level = MYSERVER_LOG_MSG_INFO);
-  int log (void* owner, string type, string location, string message,
+  int log (const void* owner, const string & type, string & message,
            bool appendNL = false, LoggingLevel level = MYSERVER_LOG_MSG_INFO);
-  int log (void* owner, string type, string location, LoggingLevel level,
-           bool appendNL, const char *fmt, ...);
-  int log (void* owner, string type, string location, LoggingLevel level,
-           bool appendNL, const char *fmt, va_list args);
-
-  int close (void* owner);
-  int close (void* owner, string type);
-  int close (void* owner, string type, string location);
-  int chown (void* owner, string &uid, string &gid);
-  int chown (void* owner, string type, string &uid, string &gid);
-  int chown (void* owner, string type, string location, string &uid, string 
&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 log (const void* owner, const string & type, const string & location,
+           string & message, bool appendNL = false,
+           LoggingLevel level = MYSERVER_LOG_MSG_INFO);
+  int log (const void* owner, const string & type, const string & location,
+           LoggingLevel level, bool appendNL, const char *fmt, ...);
+  int log (const void* owner, const string & type, const string & location,
+           LoggingLevel level, bool appendNL, const char *fmt, va_list args);
+
+  int close (const void *owner);
+  int close (const void *owner, string type);
+  int close (const void *owner, string type, string location);
+  int chown (const void *owner, string &uid, string &gid);
+  int chown (const void *owner, string type, string &uid, string &gid);
+  int chown (const void *owner, string type, string location, string &uid, 
string &gid);
+  int get (const void *owner, list<string>* l);
+  int get (const void *owner, string type, list<string>* l);
+  int get (const void *owner, string type, string location, LogStream** ls);
+  int setCycle (const void *owner, u_long cycle);
+  int setCycle (const void *owner, string type, u_long cycle);
+  int setCycle (const 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);
@@ -70,29 +72,31 @@ public:
   void setFiltersFactory (FiltersFactory* ff);
   FiltersFactory* getFiltersFactory ();
   bool empty ();
-  bool contains (string location);
-  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);
+  bool containsOwner (const void* owner);
+  bool contains (const string & location);
+  bool contains (const void* owner, const string & type);
+  bool contains (const void* owner, const string & type, const string &
+                 location);
+  int count (const void* owner);
+  int count (const void* owner, const string & type);
+  int count (const void* owner, const string & type, const string & location);
   int clear ();
-  int getOwnersList (string, list<void*>*);
+  int getOwnersList (string, list<const void*>*);
   list<string> getLoggingLevelsByNames ();
   map<LoggingLevel, string>& getLoggingLevels () { return loggingLevels; }
 private:
-  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);
+  int notify (const void* owner, const string & type, const string & location,
+              LogStreamEvent evt, void* msg = NULL, void* reply = NULL);
+  int notify (const void* owner, const string & type, LogStreamEvent evt,
+              void* msg = NULL, void* reply = NULL);
+  int notify (const void* owner, LogStreamEvent evt, void* msg = 0,
+              void* reply = NULL);
+  int add (const void *owner);
+  int add (const void *owner, string type);
+  int add (const void *owner, string type, string location, LogStream* ls);
   int computeNewLine ();
   void associateLoggingLevelsWithNames ();
-  int logWriteln (string, LoggingLevel);
+  int logWriteln (const string &, LoggingLevel);
 
   LoggingLevel level;
   Mutex* mutex;
@@ -109,12 +113,12 @@ private:
   /*!
    * For each LogStream, store the list of objects that use it.
    */
-  map<string, list<void*> > logStreamOwners;
+  map<string, list<const void*> > logStreamOwners;
 
   /*!
    * For each owner, store the LogStream objects that it owns.
    */
-  map<void*, map<string, map<string, LogStream*> > > owners;
+  map<const void*, map<string, map<string, LogStream*> > > owners;
 
   /*!
    * Store the newline string for the host operating system.
diff --git a/myserver/include/log/stream/log_stream.h 
b/myserver/include/log/stream/log_stream.h
index fb1ccef..cf83313 100644
--- a/myserver/include/log/stream/log_stream.h
+++ b/myserver/include/log/stream/log_stream.h
@@ -1,7 +1,7 @@
 /* -*- mode: c++ -*- */
 /*
   MyServer
-  Copyright (C) 2006, 2008 Free Software Foundation, Inc.
+  Copyright (C) 2006, 2008, 2009 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
@@ -68,7 +68,7 @@ public:
   int setCycle (u_long cycle);
   int needToCycle ();
   list<string>& getCycledStreams ();
-  virtual int log (string message);
+  virtual int log (const string & message);
   virtual u_long streamSize ();
   virtual int chown (int uid, int gid);
   virtual int setMode (LoggingLevel level);
diff --git a/myserver/include/log/stream/socket_stream.h 
b/myserver/include/log/stream/socket_stream.h
index f212e95..4dddbff 100644
--- a/myserver/include/log/stream/socket_stream.h
+++ b/myserver/include/log/stream/socket_stream.h
@@ -1,7 +1,7 @@
 /* -*- mode: c++ -*- */
 /*
   MyServer
-  Copyright (C) 2006, 2008 Free Software Foundation, Inc.
+  Copyright (C) 2006, 2008, 2009 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
@@ -28,7 +28,6 @@
 class SocketStream : public LogStream
 {
 public:
-
   SocketStream (FiltersFactory* filtersFactory, 
                 u_long cycleLog,
                 Stream* outStream,
diff --git a/myserver/src/conf/vhost/vhost.cpp 
b/myserver/src/conf/vhost/vhost.cpp
index 05ff4d5..315aa23 100644
--- a/myserver/src/conf/vhost/vhost.cpp
+++ b/myserver/src/conf/vhost/vhost.cpp
@@ -32,6 +32,10 @@
 #endif
 
 
+const string Vhost::accessLogType ("ACCESSLOG");
+const string Vhost::warningLogType ("WARNINGLOG");
+
+
 /*!
  *vhost costructor
  */
@@ -162,36 +166,25 @@ void Vhost::clearIPList()
       it++;
     }
   ipListDeny.clear();
-
-  /*
-  list<StringRegex*>::iterator i = ipList.begin();
-  while(i != ipList.end())
-    {
-      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);
+  return logManager->add (this, accessLogType, location, filters, cycle);
 }
 
 int
 Vhost::openWarningLog (string location, list<string>& filters, u_long cycle)
 {
-  return logManager->add (this, "WARNINGLOG", location, filters, cycle);
+  return logManager->add (this, warningLogType, location, filters, cycle);
 }
 
 int
 Vhost::openLogFiles ()
 { 
-  return logManager->count (this, "ACCESSLOG") == 0 ||
-    logManager->count (this, "WARNINGLOG") == 0;
+  return logManager->count (this, accessLogType) == 0 ||
+    logManager->count (this, warningLogType) == 0;
 }
 
 /*!
@@ -199,12 +192,12 @@ Vhost::openLogFiles ()
  *\param ip The ip to add.
  *\param isRegex Specify if the ip is specified as a regex.
  */
-void Vhost::addIP(const char *ip, int isRegex)
+void Vhost::addIP (const char *ip, int isRegex)
 {
-  std::string sTempIp(ip);
-  IpRange *pNewRange = IpRange::RangeFactory(sTempIp);
+  std::string sTempIp (ip);
+  IpRange *pNewRange = IpRange::RangeFactory (sTempIp);
   if ( pNewRange != NULL )
-    ipListAllow.push_back(pNewRange);
+    ipListAllow.push_back (pNewRange);
 }
 
 /*!
@@ -430,7 +423,8 @@ void Vhost::addHost(const char *host, int isRegex)
 int 
 Vhost::accessesLogWrite (const char* str)
 {
-  return logManager->log (this, "ACCESSLOG", string (str));
+  string msg (str);
+  return logManager->log (this, accessLogType, msg);
 }
 
 /*!
@@ -444,7 +438,7 @@ Vhost::warningsLogWrite (const char* str)
   getLocalLogFormatDate (msg, 100);
   msg.append (" -- ");
   msg.append (str);
-  return logManager->log (this, "WARNINGLOG", msg, true);
+  return logManager->log (this, warningLogType, msg, true);
 }
 
 /*!
diff --git a/myserver/src/log/log_manager.cpp b/myserver/src/log/log_manager.cpp
index ba22a7f..fc07471 100644
--- a/myserver/src/log/log_manager.cpp
+++ b/myserver/src/log/log_manager.cpp
@@ -24,8 +24,7 @@
  * \param ff The FiltersFactory object.
  * \param level The default level of logging.
  */
-LogManager::LogManager (FiltersFactory* ff,
-                        LoggingLevel level) : level (level)
+LogManager::LogManager (FiltersFactory* ff,LoggingLevel level) : level (level)
 {
   this->ff = ff;
   lsf = new LogStreamFactory ();
@@ -100,7 +99,7 @@ LogManager::clear ()
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::add (void* owner, string type, string location,
+LogManager::add (const void *owner, string type, string location,
                  list<string>& filters, u_long cycle)
 {
   mutex->lock ();
@@ -121,7 +120,7 @@ LogManager::add (void* owner, string type, string location,
       ostringstream oss;
 
       oldSize = logStreamOwners[location].size ();
-      if (!contains (owner))
+      if (!containsOwner (owner))
         {
           failure = add (owner) || add (owner, type) ||
             add (owner, type, location, logStreams[location]);
@@ -151,12 +150,12 @@ LogManager::add (void* owner, string type, string 
location,
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::add (void* owner)
+LogManager::add (const void *owner)
 {
   int failure = 1;
   if (owner)
     {
-      if (!contains (owner))
+      if (!containsOwner (owner))
         {
           map<string, map<string, LogStream*> > type;
           owners[owner] = type;
@@ -175,7 +174,7 @@ LogManager::add (void* owner)
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::add (void* owner, string type)
+LogManager::add (const void *owner, string type)
 {
   int failure = 1;
   if (type.size ())
@@ -202,25 +201,21 @@ LogManager::add (void* owner, string type)
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::add (void* owner, string type, string location, LogStream* ls)
+LogManager::add (const void *owner, string type, string location, LogStream* 
ls)
 {
   if (!contains (location))
-    {
-      logStreams[location] = ls;
-    }
+    logStreams[location] = ls;
+
   if (!contains (owner, type, location))
-    {
-      owners[owner][type][location] = ls;
-    }
-  list<void*>* l = &logStreamOwners[location];
+    owners[owner][type][location] = ls;
+
+  list<const void*>* l = &logStreamOwners[location];
   if (find (l->begin (), l->end (), owner) == l->end ())
-    {
-      l->push_back (owner);
-    }
+    l->push_back (owner);
+
   if (contains (location) && contains (owner, type, location))
-    {
-      return 0;
-    }
+    return 0;
+
   return 1;
 }
 
@@ -236,34 +231,41 @@ LogManager::add (void* owner, string type, string 
location, LogStream* ls)
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::remove (void* owner)
+LogManager::remove (const void *owner)
 {
-  mutex->lock ();
   int failure = 1;
-  if (contains (owner))
+
+
+  mutex->lock ();
+
+  if (!containsOwner (owner))
+    {
+      mutex->unlock ();
+      return 1;
+    }
+
+  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++)
     {
-      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++)
+      map<string, LogStream*> *t = &it_1->second;
+      map<string, LogStream*>::iterator it_2;
+      for (it_2 = t->begin (); it_2 != t->end (); it_2++)
         {
-          map<string, LogStream*> *t = &it_1->second;
-          map<string, LogStream*>::iterator it_2;
-          for (it_2 = t->begin (); it_2 != t->end (); it_2++)
+          logStreamOwners[it_2->first].remove (owner);
+          if (!logStreamOwners[it_2->first].size ())
             {
-              logStreamOwners[it_2->first].remove (owner);
-              if (!logStreamOwners[it_2->first].size ())
-                {
-                  delete it_2->second;
-                  logStreams.erase (it_2->first);
-                  logStreamOwners.erase (it_2->first);
-                }
+              delete it_2->second;
+              logStreams.erase (it_2->first);
+              logStreamOwners.erase (it_2->first);
             }
-          t->clear ();
         }
-      m->clear ();
-      owners.erase (owner);
-      failure = 0;
+      t->clear ();
     }
+  m->clear ();
+  owners.erase (owner);
+  failure = 0;
+
   mutex->unlock ();
   return failure;
 }
@@ -283,14 +285,14 @@ LogManager::remove (void* owner)
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::notify (void* owner, string type, string location,
-                    LogStreamEvent evt, void* message, void* reply)
+LogManager::notify (const void* owner, const string & type, const string &
+                    location, LogStreamEvent evt, void* message, void* reply)
 {
   int failure = 1;
+
   if (contains (owner, type, location))
-    {
-      failure = owners[owner][type][location]->update (evt, message, reply);
-    }
+    failure = owners[owner][type][location]->update (evt, message, reply);
+
   return failure;
 }
 
@@ -308,7 +310,7 @@ LogManager::notify (void* owner, string type, string 
location,
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::notify (void* owner, string type, LogStreamEvent evt,
+LogManager::notify (const void* owner, const string & type, LogStreamEvent evt,
                     void* message, void* reply)
 {
   int failure = 1;
@@ -318,9 +320,7 @@ LogManager::notify (void* owner, string type, 
LogStreamEvent evt,
       map<string, LogStream*> m = owners[owner][type];
       map<string, LogStream*>::iterator it;
       for (it = m.begin (); it != m.end (); it++)
-        {
-          failure |= notify (owner, type, it->first, evt, message, reply);
-        }
+        failure |= notify (owner, type, it->first, evt, message, reply);
     }
   return failure;
 }
@@ -337,19 +337,17 @@ LogManager::notify (void* owner, string type, 
LogStreamEvent evt,
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::notify (void* owner, LogStreamEvent evt, void* message,
+LogManager::notify (const void* owner, LogStreamEvent evt, void* message,
                     void* reply)
 {
   int failure = 1;
-  if (contains (owner))
+  if (containsOwner (owner))
     {
       failure = 0;
       map<string, map<string, LogStream*> > m = owners[owner];
       map<string, map<string, LogStream*> >::iterator it;
       for (it = m.begin (); it != m.end (); it++)
-        {
-          failure |= notify (owner, it->first, evt, message, reply);
-        }
+        failure |= notify (owner, it->first, evt, message, reply);
     }
   return failure;
 }
@@ -364,7 +362,7 @@ LogManager::notify (void* owner, LogStreamEvent evt, void* 
message,
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::chown (void* owner, string &uid, string &gid)
+LogManager::chown (const void *owner, string &uid, string &gid)
 {
   string message[2];
   message[0] = uid;
@@ -384,7 +382,7 @@ LogManager::chown (void* owner, string &uid, string &gid)
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::chown (void* owner, string type, string &uid, string &gid)
+LogManager::chown (const void *owner, string type, string &uid, string &gid)
 {
   string message[2];
   message[0] = uid;
@@ -404,7 +402,7 @@ LogManager::chown (void* owner, string type, string &uid, 
string &gid)
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::chown (void* owner, string type, string location, string &uid, 
string &gid)
+LogManager::chown (const void *owner, string type, string location, string 
&uid, string &gid)
 {
   string message[2];
   message[0] = uid;
@@ -425,7 +423,7 @@ LogManager::chown (void* owner, string type, string 
location, string &uid, strin
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::log (void* owner, string message, bool appendNL,
+LogManager::log (const void* owner, string & message, bool appendNL,
                  LoggingLevel level)
 {
   int failure = 0;
@@ -437,7 +435,7 @@ LogManager::log (void* owner, string message, bool appendNL,
     {
       failure = notify (owner, MYSERVER_LOG_EVT_SET_MODE,
                         static_cast<void*>(&level))
-        || notify (owner,MYSERVER_LOG_EVT_LOG, static_cast<void*>(&message));
+        || notify (owner,MYSERVER_LOG_EVT_LOG, &message);
       if (appendNL)
         {
           LoggingLevel l = MYSERVER_LOG_MSG_PLAIN;
@@ -471,8 +469,8 @@ LogManager::log (void* owner, string message, bool appendNL,
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::log (void* owner, string type, string message, bool appendNL,
-                 LoggingLevel level)
+LogManager::log (const void* owner, const string & type, string & message,
+                 bool appendNL, LoggingLevel level)
 {
   int failure = 0;
   if (level < this->level)
@@ -521,8 +519,8 @@ LogManager::log (void* owner, string type, string message, 
bool appendNL,
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::log (void* owner, string type, string location, string message,
-                 bool appendNL, LoggingLevel level)
+LogManager::log (const void* owner, const string & type, const string & 
location,
+                 string & message, bool appendNL, LoggingLevel level)
 {
   int failure = 0;
   if (level < this->level)
@@ -533,9 +531,8 @@ LogManager::log (void* owner, string type, string location, 
string message,
   try
     {
       failure = notify (owner, type, location, MYSERVER_LOG_EVT_SET_MODE,
-                        static_cast<void*>(&level))
-        || notify (owner, type, location, MYSERVER_LOG_EVT_LOG,
-                   static_cast<void*>(&message));
+                        &level) || notify (owner, type, location,
+                                           MYSERVER_LOG_EVT_LOG, &message);
 
       if (appendNL)
         {
@@ -563,8 +560,8 @@ LogManager::log (void* owner, string type, string location, 
string message,
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::log (void* owner, string type, string location, LoggingLevel level,
-                 bool appendNL, const char *fmt, ...)
+LogManager::log (const void* owner, const string & type, const string & 
location,
+                 LoggingLevel level, bool appendNL, const char *fmt, ...)
 {
   int failure = 0;
 
@@ -605,8 +602,9 @@ LogManager::log (void* owner, string type, string location, 
LoggingLevel level,
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::log (void* owner, string type, string location, LoggingLevel level,
-                 bool appendNL, const char *fmt, va_list args)
+LogManager::log (const void* owner, const string & type, const string &
+                 location, LoggingLevel level, bool appendNL, const char *fmt,
+                 va_list args)
 {
   int failure = 0;
 
@@ -655,13 +653,11 @@ LogManager::log (void* owner, string type, string 
location, LoggingLevel level,
       string message = oss.str ();
 
       failure = notify (owner, type, location, MYSERVER_LOG_EVT_SET_MODE,
-                        static_cast<void*>(&level))
-        || notify (owner, type, location, MYSERVER_LOG_EVT_LOG,
-                   static_cast<void*>(&message));
+                        static_cast<void*>(&level)) || notify (owner, type,
+                                 location, MYSERVER_LOG_EVT_LOG, &message);
 
       if (appendNL)
-        failure |= notify (owner, MYSERVER_LOG_EVT_LOG,
-                           static_cast<void*>(&newline));
+        failure |= notify (owner, MYSERVER_LOG_EVT_LOG, &newline);
     }
   catch (...)
     {
@@ -682,7 +678,7 @@ LogManager::log (void* owner, string type, string location, 
LoggingLevel level,
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::close (void* owner)
+LogManager::close (const void *owner)
 {
   return notify (owner, MYSERVER_LOG_EVT_CLOSE);
 }
@@ -697,7 +693,7 @@ LogManager::close (void* owner)
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::close (void* owner, string type)
+LogManager::close (const void *owner, string type)
 {
   return notify (owner, type, MYSERVER_LOG_EVT_CLOSE);
 }
@@ -712,7 +708,7 @@ LogManager::close (void* owner, string type)
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::close (void* owner, string type, string location)
+LogManager::close (const void *owner, string type, string location)
 {
   return notify (owner, type, location, MYSERVER_LOG_EVT_CLOSE);
 }
@@ -727,7 +723,7 @@ LogManager::close (void* owner, string type, string 
location)
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::setCycle (void* owner, u_long cycle)
+LogManager::setCycle (const void *owner, u_long cycle)
 {
   return notify (owner, MYSERVER_LOG_EVT_SET_CYCLE, 
static_cast<void*>(&cycle));
 }
@@ -743,7 +739,7 @@ LogManager::setCycle (void* owner, u_long cycle)
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::setCycle (void* owner, string type, u_long cycle)
+LogManager::setCycle (const void *owner, string type, u_long cycle)
 {
   return notify (owner, type, MYSERVER_LOG_EVT_SET_CYCLE, 
static_cast<void*>(&cycle));
 }
@@ -760,7 +756,7 @@ LogManager::setCycle (void* owner, string type, u_long 
cycle)
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::setCycle (void* owner, string type, string location, u_long cycle)
+LogManager::setCycle (const void *owner, string type, string location, u_long 
cycle)
 {
   return notify (owner, type, location, MYSERVER_LOG_EVT_SET_CYCLE,
                  static_cast<void*>(&cycle));
@@ -798,9 +794,9 @@ LogManager::getCycle (string location, u_long* cycle)
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::get (void* owner, list<string>* l)
+LogManager::get (const void *owner, list<string>* l)
 {
-  if (contains (owner))
+  if (containsOwner (owner))
     {
       l->clear ();
       map<string, map<string, LogStream*> > m = owners[owner];
@@ -830,7 +826,7 @@ LogManager::get (void* owner, list<string>* l)
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::get (void* owner, string type, list<string>* l)
+LogManager::get (const void *owner, string type, list<string>* l)
 {
   if (contains (owner, type))
     {
@@ -860,7 +856,7 @@ LogManager::get (void* owner, string type, list<string>* l)
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::get (void* owner, string type, string location, LogStream** ls)
+LogManager::get (const void *owner, string type, string location, LogStream** 
ls)
 {
   if (contains (owner, type, location))
     {
@@ -970,10 +966,10 @@ LogManager::empty ()
  * \return true if `location' is already present within the LogManager.
  */
 bool
-LogManager::contains (string location)
+LogManager::contains (const string & location)
 {
-  return logStreams.count (location) > 0 &&
-    logStreamOwners[location].size ();
+  return logStreams.count (location) > 0
+    && logStreamOwners[location].size ();
 }
 
 /*!
@@ -986,7 +982,7 @@ LogManager::contains (string location)
  * \return true if `owner' is actually present within the LogManager.
  */
 bool
-LogManager::contains (void* owner)
+LogManager::containsOwner (const void* owner)
 {
   return owners.count (owner) > 0;
 }
@@ -1001,7 +997,7 @@ LogManager::contains (void* owner)
  * \return true if the tupe <owner, type> exists.
  */
 bool
-LogManager::contains (void* owner, string type)
+LogManager::contains (const void* owner, const string & type)
 {
   return owners[owner].count (type) > 0;
 }
@@ -1017,7 +1013,8 @@ LogManager::contains (void* owner, string type)
  * \return true if the unique <owner, type, location> tuple exists.
  */
 bool
-LogManager::contains (void* owner, string type, string location)
+LogManager::contains (const void* owner, const string & type, const string &
+                      location)
 {
   return owners[owner][type].count (location) > 0 &&
     (find (logStreamOwners[location].begin (), logStreamOwners[location].end 
(), owner) !=
@@ -1034,7 +1031,7 @@ LogManager::contains (void* owner, string type, string 
location)
  * its log categories.
  */
 int
-LogManager::count (void* owner)
+LogManager::count (const void* owner)
 {
   int size = 0;
   map<string, map<string, LogStream*> > m = owners[owner];
@@ -1056,7 +1053,7 @@ LogManager::count (void* owner)
  * \return The number of LogStream objects that belong to `type'.
  */
 int
-LogManager::count (void* owner, string type)
+LogManager::count (const void* owner, const string & type)
 {
   return owners[owner][type].size ();
 }
@@ -1073,7 +1070,8 @@ LogManager::count (void* owner, string type)
  * be greater than 1, since the tuple <owner, type, location> is a key.
  */
 int
-LogManager::count (void* owner, string type, string location)
+LogManager::count (const void* owner, const string & type, const string &
+                   location)
 {
   return owners[owner][type].count (location);
 }
@@ -1087,7 +1085,7 @@ LogManager::count (void* owner, string type, string 
location)
  * \return 0 if location is owned at least by an object, 1 else.
  */
 int
-LogManager::getOwnersList (string location, list<void*>* l)
+LogManager::getOwnersList (string location, list<const void*>* l)
 {
   if (contains (location))
     {
@@ -1106,12 +1104,11 @@ LogManager::getOwnersList (string location, 
list<void*>* l)
  * \return 0 on success, 1 on error.
  */
 int
-LogManager::logWriteln (string msg, LoggingLevel l)
+LogManager::logWriteln (const string & msg, LoggingLevel l)
 {
   if (Server::getInstance ())
-    {
-      return Server::getInstance ()->logWriteln (msg.c_str (), l);
-    }
+    return Server::getInstance ()->logWriteln (msg.c_str (), l);
+
   return 1;
 }
 
diff --git a/myserver/src/log/stream/log_stream.cpp 
b/myserver/src/log/stream/log_stream.cpp
index 0245c2d..3faee99 100644
--- a/myserver/src/log/stream/log_stream.cpp
+++ b/myserver/src/log/stream/log_stream.cpp
@@ -1,6 +1,6 @@
 /*
   MyServer
-  Copyright (C) 2006, 2008 Free Software Foundation, Inc.
+  Copyright (C) 2006, 2008, 2009 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
@@ -46,7 +46,7 @@ LogStream::resetFilters ()
 }
 
 int
-LogStream::log (string message)
+LogStream::log (const string & message)
 {
   mutex->lock ();
   int success = 0;
@@ -127,38 +127,29 @@ LogStream::update (LogStreamEvent evt, void* message, 
void* reply)
   switch (evt)
     {
     case MYSERVER_LOG_EVT_SET_CYCLE:
-      {
-        return !isOpened || setCycle (*static_cast<u_long*>(message));
-      }
-      break;
+      return !isOpened || setCycle (*static_cast<u_long*>(message));
+
     case MYSERVER_LOG_EVT_LOG:
-      {
-        return !isOpened || log (*static_cast<string*>(message));
-      }
-      break;
+      return !isOpened || log (*static_cast<string*>(message));
+
     case MYSERVER_LOG_EVT_CLOSE:
-      {
-        return !isOpened || close ();
-      }
-      break;
+      return !isOpened || close ();
+
     case MYSERVER_LOG_EVT_ADD_FILTER:
-      {
-        return !isOpened || addFilter (static_cast<Filter*>(message));
-      }
-      break;
+      return !isOpened
+        || addFilter (static_cast<Filter*>(message));
+
     case MYSERVER_LOG_EVT_CHOWN:
-      {
-        return !isOpened || chown (static_cast<int*>(message)[0], 
+        return !isOpened || chown (static_cast<int*>(message)[0],
                                    static_cast<int*>(message)[1]);
-      }
-      break;
+
     case MYSERVER_LOG_EVT_SET_MODE:
-      {
-        return !isOpened || setMode (*static_cast<LoggingLevel*>(message));
-      }
-    default:
-      return 1;
+        return !isOpened
+          || setMode (*static_cast<LoggingLevel*>(message));
+
     }
+
+  return 1;
 }
 
 int
diff --git a/myserver/src/server/server.cpp b/myserver/src/server/server.cpp
index 6585797..451abfa 100644
--- a/myserver/src/server/server.cpp
+++ b/myserver/src/server/server.cpp
@@ -100,10 +100,9 @@ void
 Server::initLogManager ()
 {
   if (!logLocation.size ())
-    {
-      logLocation.assign ("console://stdout");
-    }
-  if (!logManager->contains (this))
+    logLocation.assign ("console://stdout");
+
+  if (!logManager->containsOwner (this))
     {
       list<string> filters;
       logManager->add (this, "MAINLOG", logLocation, filters, 0);
@@ -607,7 +606,8 @@ void Server::mainLoop()
           if (logLocation.find ("console://") != string::npos)
             {
               char beep[] = { static_cast<char>(0x7), '\0' };
-              logManager->log (this, "MAINLOG", logLocation, string (beep));
+              string beepStr (beep);
+              logManager->log (this, "MAINLOG", logLocation, beepStr);
             }
           logWriteln("Reloading MIMEtypes.xml");
 
@@ -627,7 +627,8 @@ void Server::mainLoop()
           if (logLocation.find ("console://") != string::npos)
             {
               char beep[] = { static_cast<char>(0x7), '\0' };
-              logManager->log (this, "MAINLOG", logLocation, string (beep));
+              string beepStr (beep);
+              logManager->log (this, "MAINLOG", logLocation, beepStr);
             }
 
           logWriteln("Rebooting...");
@@ -677,7 +678,9 @@ void Server::logWriteNTimes(string str, unsigned n)
 {
   while (n--)
     logManager->log (this, "MAINLOG", logLocation, str);
-  logManager->log(this, "MAINLOG", logLocation, string (""), true);
+
+  string msg("");
+  logManager->log (this, "MAINLOG", logLocation, msg, true);
 }
 
 /*!
@@ -732,7 +735,8 @@ void Server::displayBoot()
     {
       ostringstream err;
       err << "Error: " << e.what();
-      logManager->log (this, "MAINLOG", logLocation, err.str (), true);
+      string str = err.str ();
+      logManager->log (this, "MAINLOG", logLocation, str, true);
       return;
     }
     catch(...)
@@ -1741,7 +1745,8 @@ int Server::reboot()
   if (logLocation.find ("console://") != string::npos)
   {
     char beep[] = { static_cast<char>(0x7), '\0' };
-    logManager->log (this, "MAINLOG", logLocation, string (beep));
+    string beepStr (beep);
+    logManager->log (this, "MAINLOG", logLocation, beepStr);
   }
 
   logWriteln("Rebooting...");
@@ -2045,10 +2050,12 @@ int Server::logWriteln(char const* str, LoggingLevel 
level)
     time[len + 3] = '-';
     time[len + 4] = ' ';
     time[len + 5] = '\0';
-    if (logManager->log (this, "MAINLOG", logLocation, string (time), false, 
level))
+    string timestr (time);
+    if (logManager->log (this, "MAINLOG", logLocation, timestr, false, level))
       return 1;
   }
-  return logManager->log (this, "MAINLOG", logLocation, string (str), true, 
level);
+  string msg (str);
+  return logManager->log (this, "MAINLOG", logLocation, msg, true, level);
 }
 
 /*!
diff --git a/myserver/tests/test_log_manager.cpp 
b/myserver/tests/test_log_manager.cpp
index 6cdad40..a7ac8bc 100644
--- a/myserver/tests/test_log_manager.cpp
+++ b/myserver/tests/test_log_manager.cpp
@@ -5,12 +5,12 @@
   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, 
+
+  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/>.
 */
@@ -78,7 +78,7 @@ class TestLogManager : public CppUnit::TestFixture
   CPPUNIT_TEST (testLogOnAClosedLogStream);
   CPPUNIT_TEST (testChown);
   CPPUNIT_TEST_SUITE_END ();
-  
+
   class AnObject
   {
   };
@@ -97,7 +97,7 @@ public:
   {
     CPPUNIT_ASSERT (lm->empty ());
   }
-  
+
   void testNotEmpty ()
   {
     list<string> filters;
@@ -115,10 +115,10 @@ public:
   void testContainsOwner ()
   {
     list<string> filters;
-    
+
     lm->add (this, "test", "file://foo", filters, 0);
 
-    CPPUNIT_ASSERT (lm->contains (this));
+    CPPUNIT_ASSERT (lm->containsOwner (this));
   }
 
   void testFileStreamAdd ()
@@ -140,7 +140,7 @@ public:
     lm->add (this, "test", "file://foo", filters, 0);
     lm->remove (this);
 
-    CPPUNIT_ASSERT (!lm->contains (this));
+    CPPUNIT_ASSERT (!lm->containsOwner (this));
   }
 
   void testFileStreamLog ()
@@ -162,7 +162,7 @@ public:
 
     CPPUNIT_ASSERT (!message.compare (buf));
   }
-  
+
   void testFileStreamClose ()
   {
     list<string> filters;
@@ -236,7 +236,8 @@ public:
     lm->add (this, "test", "file://foo", filters, 0);
     lm->setLevel (MYSERVER_LOG_MSG_WARNING);
 
-    CPPUNIT_ASSERT (!lm->log (this, "test", "a message", false, 
MYSERVER_LOG_MSG_ERROR));
+    string msg ("a message");
+    CPPUNIT_ASSERT (!lm->log (this, "test", msg, false, 
MYSERVER_LOG_MSG_ERROR));
   }
 
   void testMessageLevelLessThanLogManagerOne ()
@@ -247,7 +248,8 @@ public:
     lm->add (this, "test", "file://foo", filters, 0);
     lm->setLevel (MYSERVER_LOG_MSG_WARNING);
 
-    CPPUNIT_ASSERT (lm->log (this, "test", "a message", false, 
MYSERVER_LOG_MSG_INFO));
+    string msg ("a message");
+    CPPUNIT_ASSERT (lm->log (this, "test", msg, false, MYSERVER_LOG_MSG_INFO));
   }
 
   void testMessageLevelEqualToLogManagerOne ()
@@ -258,7 +260,8 @@ public:
     lm->add (this, "test", "file://foo", filters, 0);
     lm->setLevel (MYSERVER_LOG_MSG_WARNING);
 
-    CPPUNIT_ASSERT (!lm->log (this, "test", "a message", false, 
MYSERVER_LOG_MSG_WARNING));    
+    string msg ("a message");
+    CPPUNIT_ASSERT (!lm->log (this, "test", msg, false, 
MYSERVER_LOG_MSG_WARNING));
   }
 
   void testClear ()
@@ -273,7 +276,7 @@ public:
 
     CPPUNIT_ASSERT (lm->empty ());
   }
-  
+
   void testLogThroughGzip ()
   {
     list<string> filters;
@@ -293,7 +296,7 @@ public:
     f.openFile ("fooz", File::READ | File::OPEN_IF_EXISTS);
     f.read (gzipChainComp, 64, &nbr);
     f.close ();
-    gzdc.decompress (&gzipChainComp[gzdc.headerSize ()], 
+    gzdc.decompress (&gzipChainComp[gzdc.headerSize ()],
                      nbr - gzdc.headerSize (),
                      gzipChainDecomp, 64);
     gzipChainDecomp[message.size ()] = '\0';
@@ -320,7 +323,7 @@ public:
     list<string>::iterator it;
     LogStream* ls;
     FilesUtility::deleteFile ("fooc");
-    
+
     filters.push_back ("gzip");
     lm->add (this, "test", "file://fooc", filters, cycleLog);
     lm->log (this, "test", "file://fooc", message);
@@ -328,7 +331,7 @@ public:
     f.openFile ("fooc", File::READ | File::OPEN_IF_EXISTS);
     f.read (gzipComp, 128, &nbr);
     f.close ();
-    gzdc.decompress (&gzipComp[gzdc.headerSize ()], 
+    gzdc.decompress (&gzipComp[gzdc.headerSize ()],
                      nbr - gzdc.headerSize (),
                      gzipDecomp, 128);
     gzipDecomp[message1.size ()] = '\0';
@@ -340,7 +343,7 @@ public:
         f.openFile (*it, File::READ | File::OPEN_IF_EXISTS);
         f.read (gzipComp, 128, &nbr);
         f.close ();
-        gzdc.decompress (&gzipComp[gzdc.headerSize ()], 
+        gzdc.decompress (&gzipComp[gzdc.headerSize ()],
                          nbr - gzdc.headerSize (),
                          gzipDecomp, 128);
         gzipDecomp[message.size ()] = '\0';
@@ -389,7 +392,7 @@ public:
 
     CPPUNIT_ASSERT_EQUAL (lm->count (this), 3);
   }
-  
+
   void testGetWhenNotOwningAnyLogStream ()
   {
     list<string> l;
@@ -411,7 +414,7 @@ public:
     tmp.push_back ("console://stdout");
     tmp.push_back ("console://stderr");
     lm->get (this, &l);
-    tmp.sort (); 
+    tmp.sort ();
     l.sort ();
 
     CPPUNIT_ASSERT (tmp == l);
@@ -430,12 +433,12 @@ public:
     tmp.push_back ("file://foo");
     tmp.push_back ("console://stdout");
     lm->get (this, "test", &l);
-    tmp.sort (); 
+    tmp.sort ();
     l.sort ();
 
     CPPUNIT_ASSERT (tmp == l);
   }
-  
+
   void testGetASingleExistingLogStream ()
   {
     list<string> filters;
@@ -452,12 +455,12 @@ public:
     list<string> filters;
     LogStream* ls;
     FilesUtility::deleteFile ("foo");
-    
+
     lm->add (this, "test", "file://foo", filters, 0);
 
     CPPUNIT_ASSERT (lm->get (this, "test", "file://bar", &ls));
   }
-  
+
   void testReOpen ()
   {
     list<string> filters;
@@ -559,7 +562,7 @@ public:
   {
     list<string> filters;
     AnObject anObject;
-    list<void*> l;
+    list<const void*> l;
     LogStream* ls;
     LogStream* ls1;
     FilesUtility::deleteFile ("foo");
@@ -576,7 +579,7 @@ public:
   void testGetLogStreamSharedByTheSameObject ()
   {
     list<string> filters;
-    list<void*> l;
+    list<const void*> l;
     LogStream* ls;
     LogStream* ls1;
     FilesUtility::deleteFile ("foo");
@@ -595,7 +598,7 @@ public:
     list<string> filters;
     AnObject anObject;
     AnObject anotherObject;
-    list<void*> l;
+    list<const void*> l;
     FilesUtility::deleteFile ("foo");
 
     lm->add (this, "test", "file://foo", filters, 0);
@@ -612,15 +615,15 @@ public:
     list<string> filters;
     AnObject anObject;
     AnObject anotherObject;
-    list<void*> l;
-    
+    list<const void*> l;
+
     lm->add (this, "test", "file://foo", filters, 0);
     lm->add (&anObject, "test1", "file://foo", filters, 0);
     lm->add (&anotherObject, "test2", "file://foo", filters, 0);
     lm->remove (this);
     lm->remove (&anObject);
     lm->remove (&anotherObject);
-    
+
     CPPUNIT_ASSERT (!lm->contains ("file://foo"));
   }
 
@@ -631,8 +634,8 @@ public:
 
     lm->add (this, "test", "file://foo", filters, 0);
     lm->close (this, "test", "file://foo");
-
-    CPPUNIT_ASSERT (lm->log (this, "test", "file://foo", "message"));
+    string msg ("message");
+    CPPUNIT_ASSERT (lm->log (this, "test", "file://foo", msg));
   }
 
   void testChown ()

-----------------------------------------------------------------------

Summary of changes:
 myserver/include/conf/vhost/vhost.h         |    4 +
 myserver/include/log/log_manager.h          |   88 ++++++------
 myserver/include/log/stream/log_stream.h    |    4 +-
 myserver/include/log/stream/socket_stream.h |    3 +-
 myserver/src/conf/vhost/vhost.cpp           |   36 ++---
 myserver/src/log/log_manager.cpp            |  197 +++++++++++++--------------
 myserver/src/log/stream/log_stream.cpp      |   45 +++----
 myserver/src/server/server.cpp              |   29 +++--
 myserver/tests/test_log_manager.cpp         |   65 +++++----
 9 files changed, 235 insertions(+), 236 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

[Prev in Thread] Current Thread [Next in Thread]