-
Notifications
You must be signed in to change notification settings - Fork 94
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
MINIFICPP-2494 windows event log: fix event message formatting, refactor #1900
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,8 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
#include <strsafe.h> | ||
|
||
#include <map> | ||
#include <functional> | ||
#include <codecvt> | ||
#include <regex> | ||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
|
@@ -90,10 +86,11 @@ bool MetadataWalker::for_each(pugi::xml_node &node) { | |
if (it != formatFlagMap.end()) { | ||
std::function<std::string(const std::string &)> updateFunc = [&](const std::string &input) -> std::string { | ||
if (resolve_) { | ||
auto resolved = windows_event_log_metadata_.getEventData(it->second); | ||
if (!resolved.empty()) { | ||
return resolved; | ||
const auto resolved = windows_event_log_metadata_.getEventData(it->second); | ||
if (resolved && !resolved->empty()) { | ||
return *resolved; | ||
} | ||
// TODO(szaszm): add error logging | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One behavior change in |
||
} | ||
return input; | ||
}; | ||
|
@@ -123,40 +120,25 @@ std::vector<std::string> MetadataWalker::getIdentifiers(const std::string &text) | |
return found_strings; | ||
} | ||
|
||
std::string MetadataWalker::getMetadata(METADATA metadata) const { | ||
switch (metadata) { | ||
case LOG_NAME: | ||
return log_name_; | ||
case SOURCE: | ||
return getString(metadata_, "Provider"); | ||
case TIME_CREATED: | ||
return windows_event_log_metadata_.getEventTimestamp(); | ||
case EVENTID: | ||
return getString(metadata_, "EventID"); | ||
case EVENT_RECORDID: | ||
return getString(metadata_, "EventRecordID"); | ||
case OPCODE: | ||
return getString(metadata_, "Opcode"); | ||
case TASK_CATEGORY: | ||
return getString(metadata_, "Task"); | ||
case LEVEL: | ||
return getString(metadata_, "Level"); | ||
case KEYWORDS: | ||
return getString(metadata_, "Keywords"); | ||
case EVENT_TYPE: | ||
return std::to_string(windows_event_log_metadata_.getEventTypeIndex()); | ||
case COMPUTER: | ||
return WindowsEventLogMetadata::getComputerName(); | ||
} | ||
return "N/A"; | ||
} | ||
|
||
std::map<std::string, std::string> MetadataWalker::getFieldValues() const { | ||
return fields_values_; | ||
} | ||
|
||
std::map<std::string, std::string> MetadataWalker::getIdentifiers() const { | ||
return replaced_identifiers_; | ||
Comment on lines
-154
to
-159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved inline to the header |
||
std::string MetadataWalker::getMetadata(Metadata metadata) const { | ||
using enum Metadata; | ||
switch (metadata) { | ||
case LOG_NAME: return log_name_; | ||
case SOURCE: return getString(metadata_, "Provider"); | ||
case TIME_CREATED: return windows_event_log_metadata_.getEventTimestamp(); | ||
case EVENTID: return getString(metadata_, "EventID"); | ||
case EVENT_RECORDID: return getString(metadata_, "EventRecordID"); | ||
case OPCODE: return getString(metadata_, "Opcode"); | ||
case TASK_CATEGORY: return getString(metadata_, "Task"); | ||
case LEVEL: return getString(metadata_, "Level"); | ||
case KEYWORDS: return getString(metadata_, "Keywords"); | ||
case EVENT_TYPE: return std::to_string(windows_event_log_metadata_.getEventTypeIndex()); | ||
case COMPUTER: return WindowsEventLogMetadata::getComputerName(); | ||
case USER: // TODO(szaszm): unhandled before refactoring | ||
case UNKNOWN: // TODO(szaszm): unhandled before refactoring | ||
break; | ||
} | ||
return "N/A"; | ||
} | ||
|
||
template<typename Fn> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed this to
noexcept
. There are allocations here. If they fail, the test will terminate and report failure, which is an acceptable behavior IMO.