config/option/hostsdownlimitoption.cpp
config/option/linkdownintervaloption.cpp
config/option/linkupintervaloption.cpp
+ config/option/logleveloption.cpp
config/option/nameserveroption.cpp
config/option/pingfaillimitoption.cpp
config/option/sourcenetworkinterfaceoption.cpp
dns/hostaddress.cpp
dns/timetolive.cpp
host/hoststatus.cpp
+ host/loglevel.cpp
host/messagepayload.cpp
host/networkinterfacelist.cpp
host/pinger.cpp
--- /dev/null
+/*
+The software in this package is distributed under the GNU General
+Public License version 2 (with a special exception described below).
+
+A copy of GNU General Public License (GPL) is included in this distribution,
+in the file COPYING.GPL.
+
+As a special exception, if other files instantiate templates or use macros
+or inline functions from this file, or you compile this file and link it
+with other works to produce a work based on this file, this file
+does not by itself cause the resulting work to be covered
+by the GNU General Public License.
+
+However the source code for this file must still be made available
+in accordance with section (3) of the GNU General Public License.
+
+This exception does not invalidate any other reasons why a work based
+on this file might be covered by the GNU General Public License.
+*/
+
+#include "host/loglevel.h"
+
+#include <algorithm>
+#include <map>
+
+#include <boost/assert.hpp>
+
+using namespace std;
+
+static map<string, LogLevel> log_level_string_map;
+
+LogLevel get_log_level_from_string( const string & log_level_string )
+{
+ BOOST_ASSERT( !log_level_string.empty() );
+
+ // convert to uppercase to allow the log_level to be case insensitive
+ string log_level_uppercase_string( log_level_string );
+ transform( log_level_string.begin(), log_level_string.end(),
+ log_level_uppercase_string.begin(),
+ ::toupper );
+
+ // TODO move to an init method
+ log_level_string_map[ "DEBUG" ] = LogLevel_DEBUG;
+ log_level_string_map[ "INFO" ] = LogLevel_INFO;
+ log_level_string_map[ "NOTICE" ] = LogLevel_NOTICE;
+ log_level_string_map[ "WARNING" ] = LogLevel_WARNING;
+ log_level_string_map[ "ERROR" ] = LogLevel_ERROR;
+ log_level_string_map[ "CRITICAL" ] = LogLevel_CRITICAL;
+ log_level_string_map[ "ALERT" ] = LogLevel_ALERT;
+ log_level_string_map[ "EMERGENCY" ] = LogLevel_EMERGENCY;
+
+ LogLevel log_level = log_level_string_map[ log_level_uppercase_string ];
+
+ return log_level;
+}
--- /dev/null
+/*
+ The software in this package is distributed under the GNU General
+ Public License version 2 (with a special exception described below).
+
+ A copy of GNU General Public License (GPL) is included in this distribution,
+ in the file COPYING.GPL.
+
+ As a special exception, if other files instantiate templates or use macros
+ or inline functions from this file, or you compile this file and link it
+ with other works to produce a work based on this file, this file
+ does not by itself cause the resulting work to be covered
+ by the GNU General Public License.
+
+ However the source code for this file must still be made available
+ in accordance with section (3) of the GNU General Public License.
+
+ This exception does not invalidate any other reasons why a work based
+ on this file might be covered by the GNU General Public License.
+ */
+
+#ifndef LOG_LEVEL_H
+#define LOG_LEVEL_H
+
+#include <string>
+
+enum LogLevel
+{
+ LogLevel_First = 0,
+ LogLevel_DEBUG = LogLevel_First,
+ LogLevel_INFO,
+ LogLevel_NOTICE,
+ LogLevel_WARNING,
+ LogLevel_ERROR,
+ LogLevel_CRITICAL,
+ LogLevel_ALERT,
+ LogLevel_EMERGENCY,
+ LogLevel_Last = LogLevel_EMERGENCY
+};
+
+LogLevel get_log_level_from_string( const std::string & log_level_string );
+
+#endif // LOG_LEVEL_H
--- /dev/null
+# compiler: creates the binaries
+add_executable(test_loglevel
+ test_loglevel.cpp
+ ${CMAKE_SOURCE_DIR}/src/host/loglevel.cpp
+)
+
+# linker: link the program against the libraries
+target_link_libraries(
+ test_loglevel
+ ${I2NCOMMON_LIBRARIES}
+ ${Boost_LIBRARIES}
+)
+
+# cmake: invocation via "make test"
+add_test(test_loglevel test_loglevel)
include(CMakeLists.test_pingprotocol.txt)
include(CMakeLists.test_hoststatus.txt)
include(CMakeLists.test_linkstatus.txt)
+include(CMakeLists.test_loglevel.txt)
include(CMakeLists.test_ipv4header.txt)
include(CMakeLists.test_ipv6header.txt)
include(CMakeLists.test_icmpv4header.txt)
test_pingprotocol
test_hoststatus
test_linkstatus
+ test_loglevel
test_ipv4header
test_ipv6header
test_icmpv4header
test_icmpv6header
+ test_tcpheader
)
--- /dev/null
+/*
+The software in this package is distributed under the GNU General
+Public License version 2 (with a special exception described below).
+
+A copy of GNU General Public License (GPL) is included in this distribution,
+in the file COPYING.GPL.
+
+As a special exception, if other files instantiate templates or use macros
+or inline functions from this file, or you compile this file and link it
+with other works to produce a work based on this file, this file
+does not by itself cause the resulting work to be covered
+by the GNU General Public License.
+
+However the source code for this file must still be made available
+in accordance with section (3) of the GNU General Public License.
+
+This exception does not invalidate any other reasons why a work based
+on this file might be covered by the GNU General Public License.
+*/
+
+#define BOOST_TEST_MAIN
+#define BOOST_TEST_DYN_LINK
+
+#include <boost/test/unit_test.hpp>
+
+#include "host/loglevel.h"
+
+BOOST_AUTO_TEST_SUITE( TestLogLevel )
+
+BOOST_AUTO_TEST_CASE( lowercase )
+{
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "debug" ), LogLevel_DEBUG );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "info" ), LogLevel_INFO );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "notice" ), LogLevel_NOTICE );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "warning" ), LogLevel_WARNING );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "error" ), LogLevel_ERROR );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "critical" ), LogLevel_CRITICAL );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "alert" ), LogLevel_ALERT );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "emergency" ), LogLevel_EMERGENCY );
+}
+
+BOOST_AUTO_TEST_CASE( uppercase )
+{
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "DEBUG" ), LogLevel_DEBUG );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "INFO" ), LogLevel_INFO );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "NOTICE" ), LogLevel_NOTICE );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "WARNING" ), LogLevel_WARNING );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "ERROR" ), LogLevel_ERROR );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "CRITICAL" ), LogLevel_CRITICAL );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "ALERT" ), LogLevel_ALERT );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "EMERGENCY" ), LogLevel_EMERGENCY );
+}
+
+BOOST_AUTO_TEST_CASE( mixed_case )
+{
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "DeBuG" ), LogLevel_DEBUG );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "InfO" ), LogLevel_INFO );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "NoTicE" ), LogLevel_NOTICE );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "warNing" ), LogLevel_WARNING );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "errOR" ), LogLevel_ERROR );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "critiCaL" ), LogLevel_CRITICAL );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "aleRt" ), LogLevel_ALERT );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "EmerGENCy" ), LogLevel_EMERGENCY );
+}
+
+BOOST_AUTO_TEST_CASE( misspelled )
+{
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "when" ), LogLevel_DEBUG );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "the" ), LogLevel_DEBUG );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "word" ), LogLevel_DEBUG );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "is" ), LogLevel_DEBUG );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "wrong" ), LogLevel_DEBUG );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "stick" ), LogLevel_DEBUG );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "to" ), LogLevel_DEBUG );
+ BOOST_CHECK_EQUAL( get_log_level_from_string( "DEBUG" ), LogLevel_DEBUG );
+}
+
+BOOST_AUTO_TEST_SUITE_END()