You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/02/06 21:57:19 UTC

[GitHub] [nifi-minifi-cpp] am-c-p-p opened a new pull request #728: MINIFICPP-1147 Implemented.

am-c-p-p opened a new pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728
 
 
   Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [ ] Is there a JIRA ticket associated with this PR? Is it referenced
        in the commit message?
   
   - [ ] Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
   
   - [ ] Has your PR been rebased against the latest commit within the target branch (typically master)?
   
   - [ ] Is your initial contribution a single, squashed commit?
   
   ### For code changes:
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
   - [ ] If applicable, have you updated the LICENSE file?
   - [ ] If applicable, have you updated the NOTICE file?
   
   ### For documentation related changes:
   - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
   
   ### Note:
   Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376596092
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -226,20 +229,32 @@ void ConsumeWindowsEventLog::onSchedule(const std::shared_ptr<core::ProcessConte
     }
   }
 
+  std::string mode;
+  context->getProperty(OutputFormat.getName(), mode);
+
+  writeXML_ = (mode == Both || mode == XML);
+
+  writePlainText_ = (mode == Both || mode == Plaintext);
+
+  if (writeXML_) {
+    char systemDir[MAX_PATH];
+    if (GetSystemDirectory(systemDir, sizeof(systemDir))) {
+      hMsobjsDll_ = LoadLibrary((systemDir + std::string("\\msobjs.dll")).c_str());
 
 Review comment:
   Fixed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
arpadboda commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376129464
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -286,6 +301,103 @@ wel::WindowsEventLogHandler ConsumeWindowsEventLog::getEventLogHandler(const std
   return providers_[name];
 } 
 
+
+// !!! Used a non-documented approach to resolve `%%` in XML via C:\Windows\System32\MsObjs.dll.
+// Links which mention this approach: 
+// https://social.technet.microsoft.com/Forums/Windows/en-US/340632d1-60f0-4cc5-ad6f-f8c841107d0d/translate-value-1833quot-on-impersonationlevel-and-similar-values?forum=winservergen
+// https://github.com/libyal/libevtx/blob/master/documentation/Windows%20XML%20Event%20Log%20(EVTX).asciidoc 
+// https://stackoverflow.com/questions/33498244/marshaling-a-message-table-resource
+//
+// Traverse xml and check each node, if it starts with '%%' and contains only digits, use it as key to lookup value in C:\Windows\System32\MsObjs.dll.
+void ConsumeWindowsEventLog::substituteXMLPercentageItems(pugi::xml_document& doc) {
+  if (!hMsobjsDll_) {
+    return;
+  }
+
+  struct TreeWalker: public pugi::xml_tree_walker {
+    TreeWalker(HMODULE hMsobjsDll, std::unordered_map<std::string, std::string>& xmlPercentageItemsResolutions, std::shared_ptr<logging::Logger> logger)
+      : hMsobjsDll_(hMsobjsDll), xmlPercentageItemsResolutions_(xmlPercentageItemsResolutions), logger_(logger) {
+    }
+
+    bool for_each(pugi::xml_node& node) override {
+      const std::string& nodeText = node.text().get();
+
+      auto beginNumberPos = nodeText.find("%%", 0);
 
 Review comment:
   It also begins with that, but ok. 
   You can still use stoul to convert, that drops he rest (from the first non-digit char) of the string.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] bakaid commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
bakaid commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376285952
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -226,20 +229,32 @@ void ConsumeWindowsEventLog::onSchedule(const std::shared_ptr<core::ProcessConte
     }
   }
 
+  std::string mode;
+  context->getProperty(OutputFormat.getName(), mode);
+
+  writeXML_ = (mode == Both || mode == XML);
+
+  writePlainText_ = (mode == Both || mode == Plaintext);
+
+  if (writeXML_) {
+    char systemDir[MAX_PATH];
+    if (GetSystemDirectory(systemDir, sizeof(systemDir))) {
+      hMsobjsDll_ = LoadLibrary((systemDir + std::string("\\msobjs.dll")).c_str());
 
 Review comment:
   Having this in onSchedule and `FreeLibrary` in the destructor means that if onSchedule is called multiple times (configuration reload, for example), the reference counter for this DLL will be incremented multiple times and it won't be released when the object is finally destructed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376595029
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -226,20 +229,32 @@ void ConsumeWindowsEventLog::onSchedule(const std::shared_ptr<core::ProcessConte
     }
   }
 
+  std::string mode;
+  context->getProperty(OutputFormat.getName(), mode);
+
+  writeXML_ = (mode == Both || mode == XML);
+
+  writePlainText_ = (mode == Both || mode == Plaintext);
+
+  if (writeXML_) {
+    char systemDir[MAX_PATH];
+    if (GetSystemDirectory(systemDir, sizeof(systemDir))) {
 
 Review comment:
   It is not necessary since minificpp uses Multi-Byte Character Set and macro GetSystemDirectory resolved as GetSystemDirectoryA. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376595029
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -226,20 +229,32 @@ void ConsumeWindowsEventLog::onSchedule(const std::shared_ptr<core::ProcessConte
     }
   }
 
+  std::string mode;
+  context->getProperty(OutputFormat.getName(), mode);
+
+  writeXML_ = (mode == Both || mode == XML);
+
+  writePlainText_ = (mode == Both || mode == Plaintext);
+
+  if (writeXML_) {
+    char systemDir[MAX_PATH];
+    if (GetSystemDirectory(systemDir, sizeof(systemDir))) {
 
 Review comment:
   It is not necessary since minificpp uses Multi-Byte Character Set and macro GetSystemDirectory resolved as GetSystemDirectoryA. 
   In general, if a concern that there is a possibility to accidentally use Unicode  instead of Multi-Byte Character Set (or vice versa) - it is not possible because of compilation error.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376595029
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -226,20 +229,32 @@ void ConsumeWindowsEventLog::onSchedule(const std::shared_ptr<core::ProcessConte
     }
   }
 
+  std::string mode;
+  context->getProperty(OutputFormat.getName(), mode);
+
+  writeXML_ = (mode == Both || mode == XML);
+
+  writePlainText_ = (mode == Both || mode == Plaintext);
+
+  if (writeXML_) {
+    char systemDir[MAX_PATH];
+    if (GetSystemDirectory(systemDir, sizeof(systemDir))) {
 
 Review comment:
   It is not necessary since minificpp uses Multi-Byte Character Set and macro GetSystemDirectory resolved as GetSystemDirectoryA. 
   In general, if a concern that there is a possibility to accidentally use Unicode  instead of Multi-Byte Character Set (or vice versa) - it is not possible because of compilation error.
   
   This is a common way to use any Windows API without specifying 'A' or 'W', for instance GetSystemDirectory usage in chromium:
   https://chromium.googlesource.com/chromium/src/base/+/refs/heads/master/base_paths_win.cc
   We should use Windows API this way it as well.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] arpadboda closed pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
arpadboda closed pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] bakaid commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
bakaid commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r377097030
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -226,20 +229,32 @@ void ConsumeWindowsEventLog::onSchedule(const std::shared_ptr<core::ProcessConte
     }
   }
 
+  std::string mode;
+  context->getProperty(OutputFormat.getName(), mode);
+
+  writeXML_ = (mode == Both || mode == XML);
+
+  writePlainText_ = (mode == Both || mode == Plaintext);
+
+  if (writeXML_) {
+    char systemDir[MAX_PATH];
+    if (GetSystemDirectory(systemDir, sizeof(systemDir))) {
 
 Review comment:
   If it consistently gives a compilation error when you try to use LPSTR in place of LPWSTR or vica versa, I can live with this, but I still don't see the benefit of using the macro version of the functions. We are specifically using either the A or the W versions, we don't have code where we would consistently use LPTSTRs, for example, so that it would work both with Unicode or ANSI, so that the macro version would be warranted.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] bakaid commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
bakaid commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376259988
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -226,20 +229,32 @@ void ConsumeWindowsEventLog::onSchedule(const std::shared_ptr<core::ProcessConte
     }
   }
 
+  std::string mode;
+  context->getProperty(OutputFormat.getName(), mode);
+
+  writeXML_ = (mode == Both || mode == XML);
+
+  writePlainText_ = (mode == Both || mode == Plaintext);
+
+  if (writeXML_) {
+    char systemDir[MAX_PATH];
+    if (GetSystemDirectory(systemDir, sizeof(systemDir))) {
 
 Review comment:
   Please use the A versions of the Windows API calls.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376125019
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -226,20 +229,32 @@ void ConsumeWindowsEventLog::onSchedule(const std::shared_ptr<core::ProcessConte
     }
   }
 
+  std::string mode;
+  context->getProperty(OutputFormat.getName(), mode);
+
+  writeXML_ = (mode == Both || mode == XML);
+
+  writePlainText_ = (mode == Both || mode == Plaintext);
+
+  if (writeXML_) {
+    char systemDir[MAX_PATH];
+    if (GetSystemDirectory(systemDir, sizeof(systemDir))) {
+      hMsobjsDll_ = LoadLibrary((systemDir + std::string("\\msobjs.dll")).c_str());
+      if (!hMsobjsDll_) {
 
 Review comment:
   It is checked in the beginning of substituteXMLPercentageItems.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376595029
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -226,20 +229,32 @@ void ConsumeWindowsEventLog::onSchedule(const std::shared_ptr<core::ProcessConte
     }
   }
 
+  std::string mode;
+  context->getProperty(OutputFormat.getName(), mode);
+
+  writeXML_ = (mode == Both || mode == XML);
+
+  writePlainText_ = (mode == Both || mode == Plaintext);
+
+  if (writeXML_) {
+    char systemDir[MAX_PATH];
+    if (GetSystemDirectory(systemDir, sizeof(systemDir))) {
 
 Review comment:
   It is not necessary since minificpp uses Multi-Byte Character Set and macro GetSystemDirectory resolved as GetSystemDirectoryA. 
   In general, if a concern that there is a possibility to accidentally use Unicode  instead of Multi-Byte Character Set (or vice versa) - it is not possible because of compilation error.
   
   This is a common way to use any Windows API without specifying 'A' or 'W', for instance GetSystemDirectory usage in chromium:
   https://chromium.googlesource.com/chromium/src/base/+/refs/heads/master/base_paths_win.cc
   We should use Windows API this way as well.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376681225
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -226,20 +229,32 @@ void ConsumeWindowsEventLog::onSchedule(const std::shared_ptr<core::ProcessConte
     }
   }
 
+  std::string mode;
+  context->getProperty(OutputFormat.getName(), mode);
+
+  writeXML_ = (mode == Both || mode == XML);
+
+  writePlainText_ = (mode == Both || mode == Plaintext);
+
+  if (writeXML_) {
+    char systemDir[MAX_PATH];
+    if (GetSystemDirectory(systemDir, sizeof(systemDir))) {
 
 Review comment:
   This is a common way to use any Windows API without specifying 'A' or 'W', for instance GetSystemDirectory usage in chromium:
   https://chromium.googlesource.com/chromium/src/base/+/refs/heads/master/base_paths_win.cc
   We should use Windows API this way it as well.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376126552
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -286,6 +301,103 @@ wel::WindowsEventLogHandler ConsumeWindowsEventLog::getEventLogHandler(const std
   return providers_[name];
 } 
 
+
+// !!! Used a non-documented approach to resolve `%%` in XML via C:\Windows\System32\MsObjs.dll.
+// Links which mention this approach: 
+// https://social.technet.microsoft.com/Forums/Windows/en-US/340632d1-60f0-4cc5-ad6f-f8c841107d0d/translate-value-1833quot-on-impersonationlevel-and-similar-values?forum=winservergen
+// https://github.com/libyal/libevtx/blob/master/documentation/Windows%20XML%20Event%20Log%20(EVTX).asciidoc 
+// https://stackoverflow.com/questions/33498244/marshaling-a-message-table-resource
+//
+// Traverse xml and check each node, if it starts with '%%' and contains only digits, use it as key to lookup value in C:\Windows\System32\MsObjs.dll.
+void ConsumeWindowsEventLog::substituteXMLPercentageItems(pugi::xml_document& doc) {
+  if (!hMsobjsDll_) {
+    return;
+  }
+
+  struct TreeWalker: public pugi::xml_tree_walker {
+    TreeWalker(HMODULE hMsobjsDll, std::unordered_map<std::string, std::string>& xmlPercentageItemsResolutions, std::shared_ptr<logging::Logger> logger)
+      : hMsobjsDll_(hMsobjsDll), xmlPercentageItemsResolutions_(xmlPercentageItemsResolutions), logger_(logger) {
+    }
+
+    bool for_each(pugi::xml_node& node) override {
+      const std::string& nodeText = node.text().get();
+
+      auto beginNumberPos = nodeText.find("%%", 0);
 
 Review comment:
    %% might be anywhere in the text, for instance https://docs.microsoft.com/en-us/windows/security/threat-protection/auditing/event-4662 `Properties` in Event XML. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
arpadboda commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376117286
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -286,6 +301,103 @@ wel::WindowsEventLogHandler ConsumeWindowsEventLog::getEventLogHandler(const std
   return providers_[name];
 } 
 
+
+// !!! Used a non-documented approach to resolve `%%` in XML via C:\Windows\System32\MsObjs.dll.
+// Links which mention this approach: 
+// https://social.technet.microsoft.com/Forums/Windows/en-US/340632d1-60f0-4cc5-ad6f-f8c841107d0d/translate-value-1833quot-on-impersonationlevel-and-similar-values?forum=winservergen
+// https://github.com/libyal/libevtx/blob/master/documentation/Windows%20XML%20Event%20Log%20(EVTX).asciidoc 
+// https://stackoverflow.com/questions/33498244/marshaling-a-message-table-resource
+//
+// Traverse xml and check each node, if it starts with '%%' and contains only digits, use it as key to lookup value in C:\Windows\System32\MsObjs.dll.
+void ConsumeWindowsEventLog::substituteXMLPercentageItems(pugi::xml_document& doc) {
+  if (!hMsobjsDll_) {
+    return;
+  }
+
+  struct TreeWalker: public pugi::xml_tree_walker {
+    TreeWalker(HMODULE hMsobjsDll, std::unordered_map<std::string, std::string>& xmlPercentageItemsResolutions, std::shared_ptr<logging::Logger> logger)
+      : hMsobjsDll_(hMsobjsDll), xmlPercentageItemsResolutions_(xmlPercentageItemsResolutions), logger_(logger) {
+    }
+
+    bool for_each(pugi::xml_node& node) override {
+      const std::string& nodeText = node.text().get();
+
+      auto beginNumberPos = nodeText.find("%%", 0);
 
 Review comment:
   Multiple problems here:
   
   1. This is true for anything that contains "%%" somewhere in the string
   2. the "isdigit(c)" only breaks, but doesn't result in error
   
   Becase of the two issues above the following string: "abc %%1 efg" is something we are going to consider as an error code and try to look it up. 
   
   I would suggest fixing this way:
   ```
   if (nodeText.rfind("%%", 0) != 0) {
     return true;
   } 
   std::string numText = nodeText.substr(2);
   if (!std::all_of(numText.begin(), numText.end(), ::isdigit) {
     return true;
   }
   auto n = std::stoul(numText);
   ```
   
   This guarantees that "%%" can occur only at the beginning of the text and rest of the characters should be digits.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
arpadboda commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376119197
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -286,6 +301,103 @@ wel::WindowsEventLogHandler ConsumeWindowsEventLog::getEventLogHandler(const std
   return providers_[name];
 } 
 
+
+// !!! Used a non-documented approach to resolve `%%` in XML via C:\Windows\System32\MsObjs.dll.
+// Links which mention this approach: 
+// https://social.technet.microsoft.com/Forums/Windows/en-US/340632d1-60f0-4cc5-ad6f-f8c841107d0d/translate-value-1833quot-on-impersonationlevel-and-similar-values?forum=winservergen
+// https://github.com/libyal/libevtx/blob/master/documentation/Windows%20XML%20Event%20Log%20(EVTX).asciidoc 
+// https://stackoverflow.com/questions/33498244/marshaling-a-message-table-resource
+//
+// Traverse xml and check each node, if it starts with '%%' and contains only digits, use it as key to lookup value in C:\Windows\System32\MsObjs.dll.
+void ConsumeWindowsEventLog::substituteXMLPercentageItems(pugi::xml_document& doc) {
+  if (!hMsobjsDll_) {
+    return;
+  }
+
+  struct TreeWalker: public pugi::xml_tree_walker {
+    TreeWalker(HMODULE hMsobjsDll, std::unordered_map<std::string, std::string>& xmlPercentageItemsResolutions, std::shared_ptr<logging::Logger> logger)
+      : hMsobjsDll_(hMsobjsDll), xmlPercentageItemsResolutions_(xmlPercentageItemsResolutions), logger_(logger) {
+    }
+
+    bool for_each(pugi::xml_node& node) override {
+      const std::string& nodeText = node.text().get();
+
+      auto beginNumberPos = nodeText.find("%%", 0);
+      if (std::string::npos == beginNumberPos) {
+        return true;
+      }
+      beginNumberPos += 2;
+
+      auto endNumberPos = beginNumberPos;
+
+      auto n = 0;
+      for (; endNumberPos < nodeText.size(); endNumberPos++) {
+        const auto c = nodeText[endNumberPos];
+
+        if (!isdigit(c)) {
+          break;
+        }
+
+        n = 10 * n + c - '0';
+      }
+
+      if (n) {
+        const std::string key(&nodeText[beginNumberPos], endNumberPos - beginNumberPos);
+        std::string value;
+
+        const auto it = xmlPercentageItemsResolutions_.find(key);
+        if (it == xmlPercentageItemsResolutions_.end()) {
+          LPTSTR pBuffer{};
+          if (FormatMessage(
+            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS,
+            hMsobjsDll_,
+            n,
+            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+            (LPTSTR)&pBuffer,
+            1024,
+            0
+          )) {
+            value = pBuffer;
+            LocalFree(pBuffer);
+
+            // Remove trailing white spaces.
 
 Review comment:
   ```
   value  = StringUtils::trimRight(value);
   ```
   
   ( https://github.com/apache/nifi-minifi-cpp/blob/master/libminifi/include/utils/StringUtils.h#L114 )

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] arpadboda commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
arpadboda commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376123663
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -226,20 +229,32 @@ void ConsumeWindowsEventLog::onSchedule(const std::shared_ptr<core::ProcessConte
     }
   }
 
+  std::string mode;
+  context->getProperty(OutputFormat.getName(), mode);
+
+  writeXML_ = (mode == Both || mode == XML);
+
+  writePlainText_ = (mode == Both || mode == Plaintext);
+
+  if (writeXML_) {
+    char systemDir[MAX_PATH];
+    if (GetSystemDirectory(systemDir, sizeof(systemDir))) {
+      hMsobjsDll_ = LoadLibrary((systemDir + std::string("\\msobjs.dll")).c_str());
+      if (!hMsobjsDll_) {
 
 Review comment:
   It's nice to have error handling here, although we should make sure not to call "FormatMessage" later in case this dll open failed. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376596238
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -286,6 +301,103 @@ wel::WindowsEventLogHandler ConsumeWindowsEventLog::getEventLogHandler(const std
   return providers_[name];
 } 
 
+
+// !!! Used a non-documented approach to resolve `%%` in XML via C:\Windows\System32\MsObjs.dll.
+// Links which mention this approach: 
+// https://social.technet.microsoft.com/Forums/Windows/en-US/340632d1-60f0-4cc5-ad6f-f8c841107d0d/translate-value-1833quot-on-impersonationlevel-and-similar-values?forum=winservergen
+// https://github.com/libyal/libevtx/blob/master/documentation/Windows%20XML%20Event%20Log%20(EVTX).asciidoc 
+// https://stackoverflow.com/questions/33498244/marshaling-a-message-table-resource
+//
+// Traverse xml and check each node, if it starts with '%%' and contains only digits, use it as key to lookup value in C:\Windows\System32\MsObjs.dll.
+void ConsumeWindowsEventLog::substituteXMLPercentageItems(pugi::xml_document& doc) {
+  if (!hMsobjsDll_) {
+    return;
+  }
+
+  struct TreeWalker: public pugi::xml_tree_walker {
+    TreeWalker(HMODULE hMsobjsDll, std::unordered_map<std::string, std::string>& xmlPercentageItemsResolutions, std::shared_ptr<logging::Logger> logger)
+      : hMsobjsDll_(hMsobjsDll), xmlPercentageItemsResolutions_(xmlPercentageItemsResolutions), logger_(logger) {
+    }
+
+    bool for_each(pugi::xml_node& node) override {
+      const std::string& nodeText = node.text().get();
+
+      auto beginNumberPos = nodeText.find("%%", 0);
+      if (std::string::npos == beginNumberPos) {
+        return true;
+      }
+      beginNumberPos += 2;
+
+      auto endNumberPos = beginNumberPos;
+
+      auto n = 0;
+      for (; endNumberPos < nodeText.size(); endNumberPos++) {
+        const auto c = nodeText[endNumberPos];
+
+        if (!isdigit(c)) {
+          break;
+        }
+
+        n = 10 * n + c - '0';
+      }
+
+      if (n) {
+        const std::string key(&nodeText[beginNumberPos], endNumberPos - beginNumberPos);
+        std::string value;
+
+        const auto it = xmlPercentageItemsResolutions_.find(key);
+        if (it == xmlPercentageItemsResolutions_.end()) {
+          LPTSTR pBuffer{};
+          if (FormatMessage(
+            FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS,
+            hMsobjsDll_,
+            n,
+            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+            (LPTSTR)&pBuffer,
+            1024,
+            0
+          )) {
+            value = pBuffer;
+            LocalFree(pBuffer);
+
+            // Remove trailing white spaces.
 
 Review comment:
   Fixed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [nifi-minifi-cpp] am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.

Posted by GitBox <gi...@apache.org>.
am-c-p-p commented on a change in pull request #728: MINIFICPP-1147 Implemented.
URL: https://github.com/apache/nifi-minifi-cpp/pull/728#discussion_r376681225
 
 

 ##########
 File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
 ##########
 @@ -226,20 +229,32 @@ void ConsumeWindowsEventLog::onSchedule(const std::shared_ptr<core::ProcessConte
     }
   }
 
+  std::string mode;
+  context->getProperty(OutputFormat.getName(), mode);
+
+  writeXML_ = (mode == Both || mode == XML);
+
+  writePlainText_ = (mode == Both || mode == Plaintext);
+
+  if (writeXML_) {
+    char systemDir[MAX_PATH];
+    if (GetSystemDirectory(systemDir, sizeof(systemDir))) {
 
 Review comment:
   This is a common way to use any Windows API without specifying 'A' or 'W', for instance GetSystemDirectory usage in chromium:
   https://chromium.googlesource.com/chromium/src/base/+/refs/heads/master/base_paths_win.cc
   We should use Windows API this way it as well.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services