This is an automated email from the ASF dual-hosted git repository.

aboda pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git


The following commit(s) were added to refs/heads/main by this push:
     new caf5b00  MINIFICPP-1183 Fix Windows compile errors
caf5b00 is described below

commit caf5b0026ae51132c871ddfe22055b9570866653
Author: Ferenc Gerlits <[email protected]>
AuthorDate: Tue Jul 14 11:35:50 2020 +0200

    MINIFICPP-1183 Fix Windows compile errors
    
    * Add () around std::max to work around Windows.h defining max as a macro;
    * Move the Windows-specific URL manipulation code to the new place where
      the URL is read from the command-line arguments.
    
    Signed-off-by: Arpad Boda <[email protected]>
    
    This closes #838
---
 extensions/http-curl/tests/HTTPHandlers.h              |  2 +-
 extensions/http-curl/tests/HTTPSiteToSiteTests.cpp     |  7 -------
 .../http-curl/tests/TimeoutHTTPSiteToSiteTests.cpp     |  8 --------
 .../tests => libminifi/include/utils}/HTTPUtils.h      | 18 +++++++++---------
 libminifi/test/integration/IntegrationBase.h           | 11 ++++++++++-
 5 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/extensions/http-curl/tests/HTTPHandlers.h 
b/extensions/http-curl/tests/HTTPHandlers.h
index 35472ea..1c1226f 100644
--- a/extensions/http-curl/tests/HTTPHandlers.h
+++ b/extensions/http-curl/tests/HTTPHandlers.h
@@ -572,7 +572,7 @@ public:
     if (!wait_times_.empty() && wait_times_[0] > std::chrono::seconds(0)) {
       sleep_for(wait_times_[0]);
     }
-    int chunk_count = std::max(static_cast<int>(wait_times_.size()) - 1, 0);
+    int chunk_count = (std::max)(static_cast<int>(wait_times_.size()) - 1, 0);
     mg_printf(conn, "HTTP/1.1 201 OK\r\nContent-Type: 
text/plain\r\nContent-Length: %d\r\nConnection: close\r\n\r\n", chunk_count);
     for (int chunkIdx = 0; chunkIdx < chunk_count; ++chunkIdx) {
       mg_printf(conn, "a");
diff --git a/extensions/http-curl/tests/HTTPSiteToSiteTests.cpp 
b/extensions/http-curl/tests/HTTPSiteToSiteTests.cpp
index cfea43b..26dbc18 100644
--- a/extensions/http-curl/tests/HTTPSiteToSiteTests.cpp
+++ b/extensions/http-curl/tests/HTTPSiteToSiteTests.cpp
@@ -203,13 +203,6 @@ int main(int argc, char **argv) {
   const cmd_args args = parse_cmdline_args_with_url(argc, argv);
   const bool isSecure = args.isUrlSecure();
 
-#ifdef WIN32
-  if (url.find("localhost") != std::string::npos) {
-         std::string port, scheme, path;
-         parse_http_components(url, port, scheme, path);
-         url = scheme + "://" + 
org::apache::nifi::minifi::io::Socket::getMyHostName() + ":" + port +  path;
-  }
-#endif
   {
     struct test_profile profile;
     run_variance(args.test_file, isSecure, args.url, profile);
diff --git a/extensions/http-curl/tests/TimeoutHTTPSiteToSiteTests.cpp 
b/extensions/http-curl/tests/TimeoutHTTPSiteToSiteTests.cpp
index 4603368..8b7f70d 100644
--- a/extensions/http-curl/tests/TimeoutHTTPSiteToSiteTests.cpp
+++ b/extensions/http-curl/tests/TimeoutHTTPSiteToSiteTests.cpp
@@ -148,14 +148,6 @@ int main(int argc, char **argv) {
   const cmd_args args = parse_cmdline_args_with_url(argc, argv);
   const bool isSecure = args.isUrlSecure();
 
-#ifdef WIN32
-  if (url.find("localhost") != std::string::npos) {
-         std::string port, scheme, path;
-         parse_http_components(url, port, scheme, path);
-         url = scheme + "://" + 
org::apache::nifi::minifi::io::Socket::getMyHostName() + ":" + port +  path;
-  }
-#endif
-
   const auto timeout = std::chrono::milliseconds{500};
 
   {
diff --git a/extensions/http-curl/tests/HTTPUtils.h 
b/libminifi/include/utils/HTTPUtils.h
similarity index 70%
rename from extensions/http-curl/tests/HTTPUtils.h
rename to libminifi/include/utils/HTTPUtils.h
index f8932d7..229d351 100644
--- a/extensions/http-curl/tests/HTTPUtils.h
+++ b/libminifi/include/utils/HTTPUtils.h
@@ -16,9 +16,10 @@
  * limitations under the License.
  */
 
-#ifndef NIFI_MINIFI_CPP_HTTPUTILS_H
-#define NIFI_MINIFI_CPP_HTTPUTILS_H
+#ifndef LIBMINIFI_INCLUDE_UTILS_HTTPUTILS_H_
+#define LIBMINIFI_INCLUDE_UTILS_HTTPUTILS_H_
 
+#include <string>
 #include "RegexUtils.h"
 
 /**
@@ -27,19 +28,18 @@ so we convert localhost to our local hostname.
   */
 inline bool parse_http_components(const std::string &url, std::string &port, 
std::string &scheme, std::string &path) {
 #ifdef WIN32
-       auto hostname = 
(url.find(org::apache::nifi::minifi::io::Socket::getMyHostName()) != 
std::string::npos ? org::apache::nifi::minifi::io::Socket::getMyHostName() : 
"localhost");
-       std::string regexstr = "^(http|https)://(" + hostname + 
":)([0-9]+)?(/.*)$";
+  auto hostname = 
(url.find(org::apache::nifi::minifi::io::Socket::getMyHostName()) != 
std::string::npos ? org::apache::nifi::minifi::io::Socket::getMyHostName() : 
"localhost");
+  std::string regexstr = "^(http|https)://(" + hostname + ":)([0-9]+)?(/.*)$";
 #else
-       std::string regexstr = "^(http|https)://(localhost:)([0-9]+)?(/.*)$";
+  std::string regexstr = "^(http|https)://(localhost:)([0-9]+)?(/.*)$";
 #endif
 
-       using namespace org::apache::nifi::minifi::utils;
-
+  using Regex = org::apache::nifi::minifi::utils::Regex;
   auto rgx = Regex(regexstr, {Regex::Mode::ICASE});
 
   if (rgx.match(url)) {
     auto result = rgx.getResult();
-    if(result.size() >= 5){
+    if (result.size() >= 5) {
       scheme = result[1];
       port = result[3];
       path = result[4];
@@ -49,4 +49,4 @@ inline bool parse_http_components(const std::string &url, 
std::string &port, std
   return false;
 }
 
-#endif //NIFI_MINIFI_CPP_HTTPUTILS_H
+#endif  // LIBMINIFI_INCLUDE_UTILS_HTTPUTILS_H_
diff --git a/libminifi/test/integration/IntegrationBase.h 
b/libminifi/test/integration/IntegrationBase.h
index 08b36d0..8364256 100644
--- a/libminifi/test/integration/IntegrationBase.h
+++ b/libminifi/test/integration/IntegrationBase.h
@@ -30,6 +30,7 @@
 #include "RemoteProcessorGroupPort.h"
 #include "core/ConfigurableComponent.h"
 #include "controllers/SSLContextService.h"
+#include "HTTPUtils.h"
 
 class IntegrationBase {
  public:
@@ -194,7 +195,15 @@ cmd_args parse_cmdline_args(int argc, char ** argv, const 
std::string& uri_path
 cmd_args parse_cmdline_args_with_url(int argc, char ** argv) {
   cmd_args args = parse_basic_cmdline_args(argc, argv);
   if (argc > 3) {
-    args.url = argv[3];
+    std::string url = argv[3];
+#ifdef WIN32
+    if (url.find("localhost") != std::string::npos) {
+      std::string port, scheme, path;
+      parse_http_components(url, port, scheme, path);
+      url = scheme + "://" + 
org::apache::nifi::minifi::io::Socket::getMyHostName() + ":" + port +  path;
+    }
+#endif
+    args.url = url;
   }
   return args;
 }

Reply via email to