00001 /* 00002 * anytun 00003 * 00004 * The secure anycast tunneling protocol (satp) defines a protocol used 00005 * for communication between any combination of unicast and anycast 00006 * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel 00007 * mode and allows tunneling of every ETHER TYPE protocol (e.g. 00008 * ethernet, ip, arp ...). satp directly includes cryptography and 00009 * message authentication based on the methodes used by SRTP. It is 00010 * intended to deliver a generic, scaleable and secure solution for 00011 * tunneling and relaying of packets of any protocol. 00012 * 00013 * 00014 * Copyright (C) 2007 anytun.org <satp@wirdorange.org> 00015 * 00016 * This program is free software; you can redistribute it and/or modify 00017 * it under the terms of the GNU General Public License version 2 00018 * as published by the Free Software Foundation. 00019 * 00020 * This program is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * You should have received a copy of the GNU General Public License 00026 * along with this program (see the file COPYING included with this 00027 * distribution); if not, write to the Free Software Foundation, Inc., 00028 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00029 */ 00030 00031 #ifndef _LOG_H_ 00032 #define _LOG_H_ 00033 00034 #include <string> 00035 #include <sstream> 00036 #include <syslog.h> 00037 00038 #include "threadUtils.hpp" 00039 00040 class Log; 00041 00042 class LogStringBuilder 00043 { 00044 public: 00045 LogStringBuilder(LogStringBuilder const& src); 00046 LogStringBuilder(Log& l, int p); 00047 ~LogStringBuilder(); 00048 00049 template<class T> 00050 std::ostream& operator<<(T const& value) { return stream << value; } 00051 00052 private: 00053 Log& log; 00054 int prio; 00055 std::stringstream stream; 00056 }; 00057 00058 class Log : public std::ostringstream 00059 { 00060 public: 00061 static const int FAC_USER = LOG_USER; 00062 static const int FAC_MAIL = LOG_MAIL; 00063 static const int FAC_DAEMON = LOG_DAEMON; 00064 static const int FAC_AUTH = LOG_AUTH; 00065 static const int FAC_SYSLOG = LOG_SYSLOG; 00066 static const int FAC_LPR = LOG_LPR; 00067 static const int FAC_NEWS = LOG_NEWS; 00068 static const int FAC_UUCP = LOG_UUCP; 00069 static const int FAC_CRON = LOG_CRON; 00070 static const int FAC_AUTHPRIV = LOG_AUTHPRIV; 00071 static const int FAC_FTP = LOG_FTP; 00072 static const int FAC_LOCAL0 = LOG_LOCAL0; 00073 static const int FAC_LOCAL1 = LOG_LOCAL1; 00074 static const int FAC_LOCAL2 = LOG_LOCAL2; 00075 static const int FAC_LOCAL3 = LOG_LOCAL3; 00076 static const int FAC_LOCAL4 = LOG_LOCAL4; 00077 static const int FAC_LOCAL5 = LOG_LOCAL5; 00078 static const int FAC_LOCAL6 = LOG_LOCAL6; 00079 static const int FAC_LOCAL7 = LOG_LOCAL7; 00080 00081 static const int PRIO_EMERG = LOG_EMERG; 00082 static const int PRIO_ALERT = LOG_ALERT; 00083 static const int PRIO_CRIT = LOG_CRIT; 00084 static const int PRIO_ERR = LOG_ERR; 00085 static const int PRIO_WARNING = LOG_WARNING; 00086 static const int PRIO_NOTICE = LOG_NOTICE; 00087 static const int PRIO_INFO = LOG_INFO; 00088 static const int PRIO_DEBUG = LOG_DEBUG; 00089 00090 static Log& instance(); 00091 00092 Log& setLogName(std::string newLogName); 00093 std::string getLogName() const { return logName; } 00094 Log& setFacility(int newFacility); 00095 int getFacility() const { return facility; } 00096 00097 LogStringBuilder msg(int prio=PRIO_INFO) { return LogStringBuilder(*this, prio); } 00098 00099 private: 00100 Log(); 00101 ~Log(); 00102 Log(const Log &l); 00103 void operator=(const Log &l); 00104 00105 static Log* inst; 00106 static Mutex instMutex; 00107 class instanceCleaner { 00108 public: ~instanceCleaner() { 00109 if(Log::inst != 0) 00110 delete Log::inst; 00111 } 00112 }; 00113 friend class instanceCleaner; 00114 00115 void open(); 00116 00117 Mutex mutex; 00118 friend class LogStringBuilder; 00119 00120 std::string logName; 00121 int facility; 00122 }; 00123 00124 extern Log& cLog; 00125 00126 #endif