You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by in...@apache.org on 2021/04/09 16:02:20 UTC
[hadoop] branch trunk updated: HDFS-15962. Make strcasecmp cross
platform (#2883)
This is an automated email from the ASF dual-hosted git repository.
inigoiri pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/trunk by this push:
new 3148791 HDFS-15962. Make strcasecmp cross platform (#2883)
3148791 is described below
commit 3148791da42b48db0ecb611db85eda39a7f7d452
Author: Gautham B A <ga...@gmail.com>
AuthorDate: Fri Apr 9 21:31:33 2021 +0530
HDFS-15962. Make strcasecmp cross platform (#2883)
---
.../native/libhdfspp/lib/common/CMakeLists.txt | 6 +++--
.../native/libhdfspp/lib/common/configuration.cc | 5 +++--
.../libhdfspp/lib/common/configuration_loader.cc | 7 +++---
.../src/main/native/libhdfspp/lib/fs/filesystem.cc | 2 +-
.../main/native/libhdfspp/lib/rpc/CMakeLists.txt | 5 +++--
.../main/native/libhdfspp/lib/rpc/sasl_protocol.cc | 26 ++++++++++------------
.../main/native/libhdfspp/lib/x-platform/syscall.h | 13 +++++++++++
.../libhdfspp/lib/x-platform/syscall_linux.cc | 6 +++++
.../libhdfspp/lib/x-platform/syscall_windows.cc | 7 ++++++
.../tests/x-platform/syscall_common_test.cc | 19 +++++++++++++++-
10 files changed, 71 insertions(+), 25 deletions(-)
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/CMakeLists.txt b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/CMakeLists.txt
index 87779e7..6bd7a26 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/CMakeLists.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/CMakeLists.txt
@@ -20,6 +20,8 @@ if(NEED_LINK_DL)
endif()
include_directories(${Boost_INCLUDE_DIRS} ../../include)
-add_library(common_obj OBJECT status.cc sasl_digest_md5.cc ioservice_impl.cc options.cc configuration.cc configuration_loader.cc hdfs_configuration.cc uri.cc util.cc retry_policy.cc cancel_tracker.cc logging.cc libhdfs_events_impl.cc auth_info.cc namenode_info.cc statinfo.cc fsinfo.cc content_summary.cc locks.cc config_parser.cc)
-add_library(common $<TARGET_OBJECTS:common_obj> $<TARGET_OBJECTS:uriparser2_obj>)
+add_library(common_obj OBJECT $<TARGET_OBJECTS:x_platform_obj> status.cc sasl_digest_md5.cc ioservice_impl.cc options.cc configuration.cc configuration_loader.cc hdfs_configuration.cc uri.cc util.cc retry_policy.cc cancel_tracker.cc logging.cc libhdfs_events_impl.cc auth_info.cc namenode_info.cc statinfo.cc fsinfo.cc content_summary.cc locks.cc config_parser.cc)
+add_library(common $<TARGET_OBJECTS:x_platform_obj> $<TARGET_OBJECTS:common_obj> $<TARGET_OBJECTS:uriparser2_obj>)
target_link_libraries(common ${LIB_DL})
+target_include_directories(common_obj PRIVATE ../../lib)
+target_include_directories(common PRIVATE ../../lib)
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/configuration.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/configuration.cc
index 298de1e..947214b 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/configuration.cc
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/configuration.cc
@@ -33,6 +33,7 @@
#include "configuration.h"
#include "hdfspp/uri.h"
+#include "x-platform/syscall.h"
#include <strings.h>
#include <sstream>
@@ -124,10 +125,10 @@ optional<bool> Configuration::GetBool(const std::string& key) const {
return optional<bool>();
}
- if (!strcasecmp(raw->c_str(), "true")) {
+ if (XPlatform::Syscall::StringCompareIgnoreCase(*raw, "true")) {
return std::experimental::make_optional(true);
}
- if (!strcasecmp(raw->c_str(), "false")) {
+ if (XPlatform::Syscall::StringCompareIgnoreCase(*raw, "false")) {
return std::experimental::make_optional(false);
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/configuration_loader.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/configuration_loader.cc
index 691d2ff..5301137 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/configuration_loader.cc
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/common/configuration_loader.cc
@@ -18,6 +18,7 @@
#include "configuration_loader.h"
#include "common/logging.h"
+#include "x-platform/syscall.h"
#include <fstream>
#include <strings.h>
@@ -46,17 +47,17 @@ bool is_valid_bool(const std::string& raw) {
return false;
}
- if (!strcasecmp(raw.c_str(), "true")) {
+ if (XPlatform::Syscall::StringCompareIgnoreCase(raw, "true")) {
return true;
}
- if (!strcasecmp(raw.c_str(), "false")) {
+ if (XPlatform::Syscall::StringCompareIgnoreCase(raw, "false")) {
return true;
}
return false;
}
bool str_to_bool(const std::string& raw) {
- if (!strcasecmp(raw.c_str(), "true")) {
+ if (XPlatform::Syscall::StringCompareIgnoreCase(raw, "true")) {
return true;
}
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filesystem.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filesystem.cc
index 741d6c7..e92a9ee 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filesystem.cc
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/fs/filesystem.cc
@@ -298,7 +298,7 @@ void FileSystemImpl::Connect(const std::string &server,
void FileSystemImpl::ConnectToDefaultFs(const std::function<void(const Status &, FileSystem *)> &handler) {
std::string scheme = options_.defaultFS.get_scheme();
- if (strcasecmp(scheme.c_str(), "hdfs") != 0) {
+ if (!XPlatform::Syscall::StringCompareIgnoreCase(scheme, "hdfs")) {
std::string error_message;
error_message += "defaultFS of [" + options_.defaultFS.str() + "] is not supported";
handler(Status::InvalidArgument(error_message.c_str()), nullptr);
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/rpc/CMakeLists.txt b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/rpc/CMakeLists.txt
index e5a26fb..b50134e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/rpc/CMakeLists.txt
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/rpc/CMakeLists.txt
@@ -16,7 +16,7 @@
# limitations under the License.
#
-list(APPEND rpc_object_items rpc_connection_impl.cc rpc_engine.cc namenode_tracker.cc request.cc sasl_protocol.cc sasl_engine.cc)
+list(APPEND rpc_object_items $<TARGET_OBJECTS:x_platform_obj> rpc_connection_impl.cc rpc_engine.cc namenode_tracker.cc request.cc sasl_protocol.cc sasl_engine.cc)
if (CMAKE_USING_CYRUS_SASL)
list(APPEND rpc_object_items cyrus_sasl_engine.cc)
endif (CMAKE_USING_CYRUS_SASL)
@@ -25,7 +25,8 @@ if (CMAKE_USING_GSASL)
endif (CMAKE_USING_GSASL)
add_library(rpc_obj OBJECT ${rpc_object_items})
-
+target_include_directories(rpc_obj PRIVATE ../../lib)
add_dependencies(rpc_obj proto)
add_library(rpc $<TARGET_OBJECTS:rpc_obj>)
+target_include_directories(rpc PRIVATE ../../lib)
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/rpc/sasl_protocol.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/rpc/sasl_protocol.cc
index 6fc04f7..bc9adbf 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/rpc/sasl_protocol.cc
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/rpc/sasl_protocol.cc
@@ -20,6 +20,7 @@
#include "rpc_connection.h"
#include "common/logging.h"
#include "common/optional_wrapper.h"
+#include "x-platform/syscall.h"
#include "sasl_engine.h"
#include "sasl_protocol.h"
@@ -97,20 +98,17 @@ void SaslProtocol::Authenticate(std::function<void(const Status & status, const
});
} // authenticate() method
-AuthInfo::AuthMethod ParseMethod(const std::string & method)
- {
- if (0 == strcasecmp(method.c_str(), "SIMPLE")) {
- return AuthInfo::kSimple;
- }
- else if (0 == strcasecmp(method.c_str(), "KERBEROS")) {
- return AuthInfo::kKerberos;
- }
- else if (0 == strcasecmp(method.c_str(), "TOKEN")) {
- return AuthInfo::kToken;
- }
- else {
- return AuthInfo::kUnknownAuth;
- }
+AuthInfo::AuthMethod ParseMethod(const std::string & method) {
+ if (XPlatform::Syscall::StringCompareIgnoreCase(method, "SIMPLE")) {
+ return AuthInfo::kSimple;
+ }
+ if (XPlatform::Syscall::StringCompareIgnoreCase(method, "KERBEROS")) {
+ return AuthInfo::kKerberos;
+ }
+ if (XPlatform::Syscall::StringCompareIgnoreCase(method, "TOKEN")) {
+ return AuthInfo::kToken;
+ }
+ return AuthInfo::kUnknownAuth;
} // ParseMethod()
// build_init_msg():
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall.h b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall.h
index 4f94ecb..3a77f2d 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall.h
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall.h
@@ -71,6 +71,19 @@ class Syscall {
*/
static void ClearBufferSafely(void* buffer, size_t sz_bytes);
+ /**
+ * Performs a case insensitive equality comparison for the two
+ * given strings {@link a} and {@link b}.
+ *
+ * @param a the first string parameter to compare.
+ * @param b the second string parameter to compare.
+ * @returns A boolean indicating whether to two strings are the
+ * same irrespective of their case. Returns true if they match,
+ * else false.
+ */
+ static bool StringCompareIgnoreCase(const std::string& a,
+ const std::string& b);
+
private:
static bool WriteToStdoutImpl(const char* message);
};
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall_linux.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall_linux.cc
index 9821cc7..06e96a8 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall_linux.cc
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall_linux.cc
@@ -17,6 +17,7 @@
*/
#include <fnmatch.h>
+#include <strings.h>
#include <unistd.h>
#include <cstring>
@@ -48,3 +49,8 @@ void XPlatform::Syscall::ClearBufferSafely(void* buffer,
explicit_bzero(buffer, sz_bytes);
}
}
+
+bool XPlatform::Syscall::StringCompareIgnoreCase(const std::string& a,
+ const std::string& b) {
+ return strcasecmp(a.c_str(), b.c_str()) == 0;
+}
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall_windows.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall_windows.cc
index 5a3423a..2cd9e9d 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall_windows.cc
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/lib/x-platform/syscall_windows.cc
@@ -20,6 +20,8 @@
#include <WinBase.h>
#include <Windows.h>
+#include <cstring>
+
#include "syscall.h"
#pragma comment(lib, "Shlwapi.lib")
@@ -57,3 +59,8 @@ void XPlatform::Syscall::ClearBufferSafely(void* buffer,
SecureZeroMemory(buffer, sz_bytes);
}
}
+
+bool XPlatform::Syscall::StringCompareIgnoreCase(const std::string& a,
+ const std::string& b) {
+ return _stricmp(a.c_str(), b.c_str()) == 0;
+}
diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/x-platform/syscall_common_test.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/x-platform/syscall_common_test.cc
index d68b2af..7fa3971 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/x-platform/syscall_common_test.cc
+++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tests/x-platform/syscall_common_test.cc
@@ -67,4 +67,21 @@ TEST(XPlatformSyscall, ClearBufferSafelyNumbers) {
for (const auto number : numbers) {
EXPECT_EQ(number, 0);
}
-}
\ No newline at end of file
+}
+
+TEST(XPlatformSyscall, StringCompareIgnoreCaseBasic) {
+ EXPECT_TRUE(XPlatform::Syscall::StringCompareIgnoreCase("aBcDeF", "AbCdEf"));
+ EXPECT_TRUE(XPlatform::Syscall::StringCompareIgnoreCase("a1B2c3D4e5F",
+ "A1b2C3d4E5f"));
+ EXPECT_TRUE(XPlatform::Syscall::StringCompareIgnoreCase(
+ "a!1@B#2$c%3^D&4*e(5)F", "A!1@b#2$C%3^d&4*E(5)f"));
+ EXPECT_TRUE(XPlatform::Syscall::StringCompareIgnoreCase(
+ "a<!>1@B#2$c%3^D&4*e(5)F?:", "A<!>1@b#2$C%3^d&4*E(5)f?:"));
+ EXPECT_TRUE(XPlatform::Syscall::StringCompareIgnoreCase("12345", "12345"));
+ EXPECT_TRUE(XPlatform::Syscall::StringCompareIgnoreCase("", ""));
+}
+
+TEST(XPlatformSyscall, StringCompareIgnoreCaseNegative) {
+ EXPECT_FALSE(XPlatform::Syscall::StringCompareIgnoreCase("abcd", "abcde"));
+ EXPECT_FALSE(XPlatform::Syscall::StringCompareIgnoreCase("12345", "abcde"));
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org