{
for (const auto &file : fileSet) {
if (this->m_handle->isStopped())
- ThrowExc(-999, "Async op cancelled!");
+ ThrowExcInfo(-999, "Async op cancelled!");
auto ret = this->m_dispatcher->methodCall<std::pair<int, CsDetected *>>(
CommandId::SCAN_FILE, this->m_ctx, file);
#define FORMAT(ITEMS) \
(static_cast<std::ostringstream &>(std::ostringstream() << ITEMS)).str()
-#define LOG(LEVEL, MESSAGE) Csr::Audit::Logger::log( \
- Csr::Audit::LogLevel::LEVEL, __FILENAME__, __LINE__, __func__, \
- FORMAT(MESSAGE))
+#define LOG(LEVEL, MESSAGE) Csr::Audit::Logger::log( \
+ LEVEL, __FILENAME__, __LINE__, __func__, FORMAT(MESSAGE)) \
-#define ERROR(MESSAGE) LOG(Error, MESSAGE)
-#define WARN(MESSAGE) LOG(Warning, MESSAGE)
-#define INFO(MESSAGE) LOG(Info, MESSAGE)
+#define ERROR(MESSAGE) LOG(Csr::Audit::LogLevel::Error, MESSAGE)
+#define WARN(MESSAGE) LOG(Csr::Audit::LogLevel::Warning, MESSAGE)
+#define INFO(MESSAGE) LOG(Csr::Audit::LogLevel::Info, MESSAGE)
#if !defined(NDEBUG)
-#define DEBUG(MESSAGE) LOG(Debug, MESSAGE)
-#define TRACE(MESSAGE) LOG(Trace, MESSAGE)
+#define DEBUG(MESSAGE) LOG(Csr::Audit::LogLevel::Debug, MESSAGE)
+#define TRACE(MESSAGE) LOG(Csr::Audit::LogLevel::Trace, MESSAGE)
#else
#define DEBUG(MESSAGE) do {} while (false)
#define TRACE(MESSAGE) do {} while (false)
namespace Csr {
Exception::Exception(int ec, const char *file, const char *function, unsigned int line,
- const std::string &message) noexcept :
+ Audit::LogLevel level, const std::string &message) noexcept :
m_ec(ec),
m_message(FORMAT("[" << file << ":" << line << " " << function << "()]" << message))
{
- ERROR(this->m_message);
+ LOG(level, this->m_message);
}
const char *Exception::what() const noexcept
class API Exception : public std::exception {
public:
Exception(int ec, const char *file, const char *function, unsigned int line,
- const std::string &message) noexcept;
+ Audit::LogLevel level, const std::string &message) noexcept;
virtual ~Exception() = default;
virtual const char *what() const noexcept final;
} // namespace Csr
-#define ThrowExc(ec, MESSAGE) \
- throw Csr::Exception(ec, __FILE__, __FUNCTION__, __LINE__, FORMAT(MESSAGE))
+#define __CSR_THROW(ec, LEVEL, MESSAGE) \
+ throw Csr::Exception(ec, __FILE__, __FUNCTION__, __LINE__, \
+ Csr::Audit::LogLevel::LEVEL, FORMAT(MESSAGE))
+
+#define ThrowExc(ec, MESSAGE) __CSR_THROW(ec, Error, MESSAGE)
+#define ThrowExcWarn(ec, MESSAGE) __CSR_THROW(ec, Warning, MESSAGE)
+#define ThrowExcInfo(ec, MESSAGE) __CSR_THROW(ec, Info, MESSAGE)
+#define ThrowExcDebug(ec, MESSAGE) __CSR_THROW(ec, Debug, MESSAGE)
void *handle = dlopen(enginePath.c_str(), RTLD_LAZY);
if (handle == nullptr)
- ThrowExc(CSR_ERROR_ENGINE_NOT_EXIST, "engine dlopen error. path: " << enginePath <<
- " errno: " << errno);
+ ThrowExcWarn(CSR_ERROR_ENGINE_NOT_EXIST, "engine dlopen error. path: " <<
+ enginePath << " errno: " << errno);
this->m_pc.dlhandle = handle;
if (checkAccess && !isReadable(path)) {
const int err = errno;
if (err == ENOENT)
- ThrowExc(CSR_ERROR_FILE_DO_NOT_EXIST, "File do not exist: " << target);
+ ThrowExcWarn(CSR_ERROR_FILE_DO_NOT_EXIST, "File do not exist: " << target);
else if (err == EACCES)
ThrowExc(CSR_ERROR_PERMISSION_DENIED,
"Perm denied to get real path: " << target);
auto statptr = getStat(fpath);
if (statptr == nullptr)
- ThrowExc(CSR_ERROR_FILE_DO_NOT_EXIST, "file not exist or no permission: " << fpath);
+ ThrowExcWarn(CSR_ERROR_FILE_DO_NOT_EXIST, "file not exist or no permission: " <<
+ fpath);
else if (!S_ISREG(statptr->st_mode) && !S_ISDIR(statptr->st_mode))
ThrowExc(CSR_ERROR_FILE_SYSTEM, "file type is not reguler or dir: " << fpath);
{
auto statptr = getStat(dirpath);
if (statptr == nullptr)
- ThrowExc(CSR_ERROR_FILE_DO_NOT_EXIST, "directory not exist or no permission: " << dirpath);
+ ThrowExcWarn(CSR_ERROR_FILE_DO_NOT_EXIST, "directory not exist or no "
+ "permission: " << dirpath);
else if (!S_ISDIR(statptr->st_mode))
ThrowExc(CSR_ERROR_FILE_SYSTEM, "file type is not directory: " << dirpath);
else
this->m_cs = std::make_shared<CsLoader>(CS_ENGINE_PATH, ENGINE_DIR,
ENGINE_RW_WORKING_DIR);
} catch (const Exception &e) {
- ERROR("Excetpion in content screening loader: " << e.what() <<
- " error: " << e.error() << " treat it as ENGINE_NOT_EXIST.");
+ WARN("Excetpion in content screening loader: " << e.what() <<
+ " error: " << e.error() << " treat it as ENGINE_NOT_EXIST.");
}
try {
this->m_wp = std::make_shared<WpLoader>(WP_ENGINE_PATH, ENGINE_DIR,
ENGINE_RW_WORKING_DIR);
} catch (const Exception &e) {
- ERROR("Exception in web protection loader: " << e.what() <<
- " error: " << e.error() << " treat it as ENGINE_NOT_EXIST.");
+ WARN("Exception in web protection loader: " << e.what() <<
+ " error: " << e.error() << " treat it as ENGINE_NOT_EXIST.");
}
this->m_cslogic.reset(new CsLogic(this->m_cs, this->m_db));
void *handle = dlopen(enginePath.c_str(), RTLD_LAZY);
if (handle == nullptr)
- ThrowExc(CSR_ERROR_ENGINE_NOT_EXIST, "engine dlopen error. path: " << enginePath <<
- " errno: " << errno);
+ ThrowExcWarn(CSR_ERROR_ENGINE_NOT_EXIST, "engine dlopen error. path: " <<
+ enginePath << " errno: " << errno);
this->m_pc.dlhandle = handle;