Replaced couts with isc::log mechanisms in user_chk DHCP hook library.
AM_CXXFLAGS += $(WARNING_NO_MISSING_FIELD_INITIALIZERS_CFLAG)
# Define rule to build logging source files from message file
-# hooks_messages.h hooks_messages.cc: s-messages
+user_chk_messages.h user_chk_messages.cc: s-messages
-# s-messages: hooks_messages.mes
-# $(top_builddir)/src/lib/log/compiler/message $(top_srcdir)/src/lib/hooks/hooks_messages.mes
-# touch $@
+s-messages: user_chk_messages.mes
+ $(top_builddir)/src/lib/log/compiler/message $(top_srcdir)/src/hooks/dhcp/user_chk/user_chk_messages.mes
+ touch $@
# Tell automake that the message files are built as part of the build process
# (so that they are built before the main library is built).
-# BUILT_SOURCES = hooks_messages.h hooks_messages.cc
-BUILT_SOURCES =
+BUILT_SOURCES = user_chk_messages.h user_chk_messages.cc
# Ensure that the message file is included in the distribution
EXTRA_DIST =
# Get rid of generated message files on a clean
-# CLEANFILES = *.gcno *.gcda hooks_messages.h hooks_messages.cc s-messages
-CLEANFILES = *.gcno *.gcda
+CLEANFILES = *.gcno *.gcda user_chk_messages.h user_chk_messages.cc s-messages
lib_LTLIBRARIES = libdhcp_user_chk.la
libdhcp_user_chk_la_SOURCES =
libdhcp_user_chk_la_SOURCES += load_unload.cc
libdhcp_user_chk_la_SOURCES += subnet_select_co.cc
libdhcp_user_chk_la_SOURCES += user.cc user.h
+libdhcp_user_chk_la_SOURCES += user_chk_log.cc user_chk_log.h
libdhcp_user_chk_la_SOURCES += user_data_source.cc user_data_source.h
libdhcp_user_chk_la_SOURCES += user_file.cc user_file.h
libdhcp_user_chk_la_SOURCES += user_registry.cc user_registry.h
libdhcp_user_chk_la_SOURCES += version.cc
-#nodist_libdhcp_user_chk_la_SOURCES = hooks_messages.cc hooks_messages.h
-nodist_libdhcp_user_chk_la_SOURCES =
+nodist_libdhcp_user_chk_la_SOURCES = user_chk_messages.cc user_chk_messages.h
libdhcp_user_chk_la_CXXFLAGS = $(AM_CXXFLAGS)
libdhcp_user_chk_la_CPPFLAGS = $(AM_CPPFLAGS) $(LOG4CPLUS_INCLUDES)
// load_unload.cc
#include <hooks/hooks.h>
+#include <user_chk_log.h>
#include <user_registry.h>
#include <user_file.h>
#include <iostream>
#include <fstream>
+#include <errno.h>
using namespace isc::hooks;
int load(LibraryHandle&) {
+ isc::log::MessageInitializer::loadDictionary();
+
// non-zero indicates an error.
int ret_val = 0;
try {
// Open up the output file for user_chk results.
user_chk_output.open(user_chk_output_fname,
std::fstream::out | std::fstream::app);
-
+ int sav_errno = errno;
if (!user_chk_output) {
- std::cout << "UserCheckHook: cannot open user check output file: "
- << user_chk_output_fname << std::endl;
- ret_val = 1;
+ isc_throw(isc::Unexpected, "Cannot open output file: "
+ << user_chk_output_fname
+ << " reason: " << strerror(sav_errno));
}
}
catch (const std::exception& ex) {
- std::cout << "UserCheckHook: loading user_chk hook lib failed:"
- << ex.what() << std::endl;
+ LOG_ERROR(user_chk_logger, USER_CHK_HOOK_LOAD_ERROR).arg(ex.what());
ret_val = 1;
}
}
int unload() {
- user_registry.reset();
- if (user_chk_output.is_open()) {
- user_chk_output.close();
+ try {
+ user_registry.reset();
+ if (user_chk_output.is_open()) {
+ user_chk_output.close();
+ }
+ } catch (const std::exception& ex) {
+ // On the off chance something goes awry, catch it and log it.
+ // @todo Not sure if we should return a non-zero result or not.
+ LOG_ERROR(user_chk_logger, USER_CHK_HOOK_UNLOAD_ERROR).arg(ex.what());
}
return (0);
#include <dhcp/pkt6.h>
#include <dhcpsrv/subnet.h>
#include <user_registry.h>
+#include <user_chk_log.h>
#include <fstream>
#include <string>
// This callout is called at the "subnet4_select" hook.
int subnet4_select(CalloutHandle& handle) {
if (!user_registry) {
- std::cout << "UserCheckHook: UserRegistry is null!" << std::endl;
+ LOG_ERROR(user_chk_logger, USER_CHK_SUBNET4_SELECT_REGISTRY_NULL);
return (1);
}
false);
}
} catch (const std::exception& ex) {
- std::cout << "UserCheckHook: Exception in subnet4_select callout:"
- << ex.what() << std::endl;
-
+ LOG_ERROR(user_chk_logger, USER_CHK_SUBNET4_SELECT_ERROR)
+ .arg(ex.what());
return (1);
}
// This callout is called at the "subnet6_select" hook.
int subnet6_select(CalloutHandle& handle) {
if (!user_registry) {
- std::cout << "UserCheckHook: UserRegistry is null!" << std::endl;
+ LOG_ERROR(user_chk_logger, USER_CHK_SUBNET4_SELECT_REGISTRY_NULL);
return (1);
}
false);
}
} catch (const std::exception& ex) {
- std::cout << "UserCheckHook: Exception in subnet6_select callout:" << ex.what() << std::endl;
+ LOG_ERROR(user_chk_logger, USER_CHK_SUBNET6_SELECT_ERROR)
+ .arg(ex.what());
return (1);
}
libdhcp_user_chk_unittests_SOURCES += ../subnet_select_co.cc
libdhcp_user_chk_unittests_SOURCES += ../version.cc
libdhcp_user_chk_unittests_SOURCES += ../user.cc ../user.h
+libdhcp_user_chk_unittests_SOURCES += ../user_chk_log.cc ../user_chk_log.h
+libdhcp_user_chk_unittests_SOURCES += ../user_chk_messages.cc ../user_chk_messages.h
libdhcp_user_chk_unittests_SOURCES += ../user_data_source.cc ../user_data_source.h
libdhcp_user_chk_unittests_SOURCES += ../user_file.cc ../user_file.h
libdhcp_user_chk_unittests_SOURCES += ../user_registry.cc ../user_registry.h
libdhcp_user_chk_unittests_LDADD = $(top_builddir)/src/lib/log/libb10-log.la
libdhcp_user_chk_unittests_LDADD += $(top_builddir)/src/lib/util/libb10-util.la
+libdhcp_user_chk_unittests_LDADD += $(top_builddir)/src/lib/hooks/libb10-hooks.la
libdhcp_user_chk_unittests_LDADD += $(top_builddir)/src/lib/dhcp/libb10-dhcp++.la
libdhcp_user_chk_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libb10-exceptions.la
libdhcp_user_chk_unittests_LDADD += $(top_builddir)/src/lib/cc/libb10-cc.la
--- /dev/null
+// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+/// Defines the logger used by the NSAS
+
+#include <user_chk_log.h>
+
+isc::log::Logger user_chk_logger("user_chk");
--- /dev/null
+// Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef USER_CHK_LOG_H
+#define USER_CHK_LOG_H
+
+#include <log/message_initializer.h>
+#include <log/macros.h>
+#include <user_chk_messages.h>
+
+/// @brief User Check Logger
+///
+/// Define the logger used to log messages. We could define it in multiple
+/// modules, but defining in a single module and linking to it saves time and
+/// space.
+extern isc::log::Logger user_chk_logger;
+
+#endif // USER_CHK_LOG_H
--- /dev/null
+# Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+
+% USER_CHK_HOOK_LOAD_ERROR DHCP UserCheckHook could not be loaded: %1
+This is an error message issued when the DHCP UserCheckHook could not be loaded.
+The exact cause should be explained in the log message. User subnet selection will revert to default processing.
+
+% USER_CHK_HOOK_UNLOAD_ERROR DHCP UserCheckHook an error occurred unloading the library: %1
+This is an error message issued when an error occurs while unloading the
+UserCheckHook library. This is unlikely to occur and normal operations of the
+library will likely resume when it is next loaded.
+
+% USER_CHK_SUBNET4_SELECT_ERROR DHCP UserCheckHook an unexpected error occured in subnet4_select callout: %1
+This is an error message issued when the DHCP UserCheckHook subnet4_select hook
+encounters an unexpected error. The message should contain a more detailed
+explanation.
+
+% USER_CHK_SUBNET4_SELECT_REGISTRY_NULL DHCP UserCheckHook UserRegistry has not been created.
+This is an error message issued when the DHCP UserCheckHook subnet4_select hook
+has been invoked but the UserRegistry has not been created. This is a
+programmatic error and should not occur.
+
+% USER_CHK_SUBNET6_SELECT_ERROR DHCP UserCheckHook an unexpected error occured in subnet6_select callout: %1
+This is an error message issued when the DHCP UserCheckHook subnet6_select hook
+encounters an unexpected error. The message should contain a more detailed
+explanation.
+
+% USER_CHK_SUBNET6_SELECT_REGISTRY_NULL DHCP UserCheckHook UserRegistry has not been created.
+This is an error message issued when the DHCP UserCheckHook subnet6_select hook
+has been invoked but the UserRegistry has not been created. This is a
+programmatic error and should not occur.
#include <user_file.h>
#include <boost/foreach.hpp>
+#include <errno.h>
UserFile::UserFile(const std::string& fname) : fname_(fname) {
if (fname_.empty()) {
}
ifs_.open(fname_.c_str(), std::ifstream::in);
+ int sav_error = errno;
if (!ifs_.is_open()) {
- isc_throw(UserFileError, "cannot open file:" << fname_);
+ isc_throw(UserFileError, "cannot open file:" << fname_
+ << " reason: " << strerror(sav_error));
}
setOpenFlag(true);