Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FHOSTLOOKUP:: FIX ABSENT FEED_NAME IN CASE OF NON-TEXT DB #202

Merged
merged 2 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions samples/fhostlookup/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ bool Generator::LoadConfig(const rapidjson::Document &configuration) {
return this->LoadTextFile(db);
} else {
DARWIN_LOG_CRITICAL("HostLookup:: Generator:: Unknown 'db_type'");
return false;
}
return false; // Put it there just in case.

return false;
}

bool Generator::LoadTextFile(const std::string& filename) {
Expand All @@ -95,13 +95,8 @@ bool Generator::LoadTextFile(const std::string& filename) {
_database.insert({buf,{"", 100}});
}
}
this->LoadFeedNameFromFile(filename);
file.close();

// Get feed name from file name
buf = darwin::files_utils::GetNameFromPath(filename); // Filename already proven valid
darwin::files_utils::ReplaceExtension(buf, "");
this->_feed_name = buf;

return true;
}

Expand All @@ -126,12 +121,18 @@ bool Generator::LoadJsonFile(const std::string& filename, const db_type type) {
if (type == db_type::json) {
ret = this->LoadJsonDatabase(database);
} else if (type == db_type::rsyslog) {
this->LoadFeedNameFromFile(filename);
ret = this->LoadRsyslogDatabase(database);
}
file.close();
return ret;
}

void Generator::LoadFeedNameFromFile(const std::string& filename) {
this->_feed_name = darwin::files_utils::GetNameFromPath(filename);
darwin::files_utils::ReplaceExtension(this->_feed_name, "");
}

bool Generator::LoadJsonDatabase(const rapidjson::Document& database) {
DARWIN_LOGGER;
if (not database.HasMember("feed_name") or not database["feed_name"].IsString()) {
Expand Down
1 change: 1 addition & 0 deletions samples/fhostlookup/Generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Generator: public AGenerator {

bool LoadTextFile(const std::string& filename);
bool LoadJsonFile(const std::string& filename, const db_type type);
void LoadFeedNameFromFile(const std::string& filename);
bool LoadJsonDatabase(const rapidjson::Document& database);
bool LoadJsonEntry(const rapidjson::Value& entry);
bool LoadRsyslogDatabase(const rapidjson::Document& database);
Expand Down