mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-29 19:24:26 +03:00
Sep_24_2023-Dev
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <sys/syscall.h>
|
||||
#include <dirent.h>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
@@ -49,6 +50,24 @@ exists(const string &path)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
isDirectory(const string &path)
|
||||
{
|
||||
dbgFlow(D_INFRA_UTILS) << "Checking if path is a directory. Path: " << path;
|
||||
struct stat buffer;
|
||||
if (stat(path.c_str(), &buffer) != 0) {
|
||||
dbgTrace(D_INFRA_UTILS) << "Path does not exists. Path: " << path;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (buffer.st_mode & S_IFDIR) {
|
||||
dbgTrace(D_INFRA_UTILS) << "Path is a directory. Path: " << path;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
makeDir(const string &path, mode_t permission)
|
||||
{
|
||||
@@ -356,4 +375,20 @@ regexReplace(const char *file, int line, const string &sample, const regex ®e
|
||||
|
||||
}// namespace Regex
|
||||
|
||||
namespace Strings
|
||||
{
|
||||
|
||||
string
|
||||
removeTrailingWhitespaces(string str)
|
||||
{
|
||||
str.erase(
|
||||
find_if(str.rbegin(), str.rend(), [] (char c) { return !isspace(c); }).base(),
|
||||
str.end()
|
||||
);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
} // namespace Strings
|
||||
|
||||
} // namespace NGEN
|
||||
|
@@ -98,8 +98,20 @@ TEST_F(AgentCoreUtilUT, printTest)
|
||||
EXPECT_EQ(NGEN::Filesystem::convertToHumanReadable(1024*gigabyte), "1024.00 GB");
|
||||
}
|
||||
|
||||
|
||||
TEST_F(AgentCoreUtilUT, fileBasenameTest)
|
||||
{
|
||||
EXPECT_EQ(NGEN::Filesystem::getFileName("/test/base/file/name"), "name");
|
||||
}
|
||||
|
||||
TEST_F(AgentCoreUtilUT, isDirectoryTest)
|
||||
{
|
||||
mkdir("./test", 0400);
|
||||
EXPECT_EQ(NGEN::Filesystem::isDirectory("/test/base/file/name"), false);
|
||||
EXPECT_EQ(NGEN::Filesystem::isDirectory("./test"), true);
|
||||
}
|
||||
|
||||
TEST_F(AgentCoreUtilUT, removeTrailingWhitespacesTest)
|
||||
{
|
||||
string str_with_trailing_whitespace = "str_with_trailing_whitespace\n\n\n\r \n\n\r";
|
||||
EXPECT_EQ(NGEN::Strings::removeTrailingWhitespaces(str_with_trailing_whitespace), "str_with_trailing_whitespace");
|
||||
}
|
||||
|
@@ -141,7 +141,6 @@ Environment::Impl::init()
|
||||
void
|
||||
Environment::Impl::fini()
|
||||
{
|
||||
global.deactivate();
|
||||
}
|
||||
|
||||
void
|
||||
|
@@ -143,7 +143,8 @@ enum class Notification {
|
||||
SDWAN_POLICY_UPDATE,
|
||||
SDWAN_POLICY_UPDATE_ERROR,
|
||||
SDWAN_POLICY_UPDATE_LOG,
|
||||
SDWAN_POLICY_UPDATE_ERROR_LOG
|
||||
SDWAN_POLICY_UPDATE_ERROR_LOG,
|
||||
SDWAN_POLICY_WARNING_LOG
|
||||
};
|
||||
|
||||
enum class IssuingEngine {
|
||||
|
@@ -25,6 +25,7 @@ namespace Filesystem
|
||||
{
|
||||
|
||||
bool exists(const std::string &path);
|
||||
bool isDirectory(const std::string &path);
|
||||
|
||||
bool makeDir(const std::string &path, mode_t permission = S_IRWXU);
|
||||
bool makeDirRecursive(const std::string &path, mode_t permission = S_IRWXU);
|
||||
@@ -75,6 +76,13 @@ regexReplace(
|
||||
|
||||
} // namespace Regex
|
||||
|
||||
namespace Strings
|
||||
{
|
||||
|
||||
std::string removeTrailingWhitespaces(std::string str);
|
||||
|
||||
} // namespace Strings
|
||||
|
||||
} // namespace NGEN
|
||||
|
||||
#endif // __AGENT_CORE_UTILITIES_H__
|
||||
|
@@ -19,7 +19,10 @@ extern const string unnamed_service;
|
||||
|
||||
LogGen::~LogGen()
|
||||
{
|
||||
if (send_log) Singleton::Consume<I_Logging>::by<LogGen>()->sendLog(log);
|
||||
try {
|
||||
if (send_log) Singleton::Consume<I_Logging>::by<LogGen>()->sendLog(log);
|
||||
} catch (...) {
|
||||
}
|
||||
}
|
||||
|
||||
LogGen &
|
||||
|
@@ -252,6 +252,7 @@ TagAndEnumManagement::convertToString(const Notification ¬ification)
|
||||
case Notification::SDWAN_POLICY_UPDATE_ERROR: return "8d2db6ea-30b7-11ec-8d3d-0242ac130003";
|
||||
case Notification::SDWAN_POLICY_UPDATE_LOG: return "97cb79e1-e873-4f28-b123-5e19f8dd6f99";
|
||||
case Notification::SDWAN_POLICY_UPDATE_ERROR_LOG: return "44ca5755-07a2-483c-b756-b7df444e175c";
|
||||
case Notification::SDWAN_POLICY_WARNING_LOG: return "c58d490e-6aa0-43da-bfaa-7edad0a57b7a";
|
||||
}
|
||||
|
||||
dbgAssert(false) << "Reached impossible notification value of: " << static_cast<int>(notification);
|
||||
|
Reference in New Issue
Block a user