From 2d63ae6e860442689671b75acbf8a4403ad7e953 Mon Sep 17 00:00:00 2001
From: 761417898 <761417898@qq.com>
Date: Mon, 26 Jan 2026 12:24:35 +0800
Subject: [PATCH 1/2] Support session with CPP conditional compilation for SSL.
---
example/client-cpp-example/src/CMakeLists.txt | 157 ++++++++++++------
iotdb-client/client-cpp/pom.xml | 3 +
.../client-cpp/src/main/CMakeLists.txt | 50 ++++--
.../client-cpp/src/main/SessionConnection.cpp | 6 +
.../client-cpp/src/main/SessionConnection.h | 6 +-
.../client-cpp/src/main/ThriftConnection.cpp | 6 +
.../client-cpp/src/main/ThriftConnection.h | 4 +
.../client-cpp/src/test/CMakeLists.txt | 92 ++++++----
8 files changed, 224 insertions(+), 100 deletions(-)
diff --git a/example/client-cpp-example/src/CMakeLists.txt b/example/client-cpp-example/src/CMakeLists.txt
index 6d87631ab576b..1ee249bfb803e 100644
--- a/example/client-cpp-example/src/CMakeLists.txt
+++ b/example/client-cpp-example/src/CMakeLists.txt
@@ -28,12 +28,23 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/thrift/include)
# Add cpp-client include directory
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/client/include)
-FIND_PACKAGE(OpenSSL REQUIRED)
-IF(OpenSSL_FOUND)
- MESSAGE(STATUS "OpenSSL found: ${OPENSSL_VERSION}")
- INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
+# =========================
+# SSL option (default OFF)
+# =========================
+option(WITH_SSL "Build with SSL support" OFF)
+
+IF(WITH_SSL)
+ FIND_PACKAGE(OpenSSL REQUIRED)
+ IF(OpenSSL_FOUND)
+ MESSAGE(STATUS "OpenSSL found: ${OPENSSL_VERSION}")
+ INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
+ ADD_DEFINITIONS(-DWITH_SSL=1)
+ ELSE()
+ MESSAGE(FATAL_ERROR "OpenSSL not found, but WITH_SSL is enabled")
+ ENDIF()
ELSE()
- MESSAGE(FATAL_ERROR "OpenSSL not found")
+ MESSAGE(STATUS "Building without SSL support")
+ ADD_DEFINITIONS(-DWITH_SSL=0)
ENDIF()
FIND_PACKAGE(Boost REQUIRED)
@@ -50,53 +61,91 @@ ADD_EXECUTABLE(TableModelSessionExample TableModelSessionExample.cpp)
ADD_EXECUTABLE(MultiSvrNodeClient MultiSvrNodeClient.cpp)
IF(MSVC)
- TARGET_LINK_LIBRARIES(SessionExample
- iotdb_session
- "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(AlignedTimeseriesSessionExample
- iotdb_session
- "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(TableModelSessionExample
- iotdb_session
- "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(MultiSvrNodeClient
- iotdb_session
- "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
- OpenSSL::SSL
- OpenSSL::Crypto
- )
+ IF(WITH_SSL)
+ TARGET_LINK_LIBRARIES(SessionExample
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(AlignedTimeseriesSessionExample
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(TableModelSessionExample
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(MultiSvrNodeClient
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ ELSE()
+ TARGET_LINK_LIBRARIES(SessionExample
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ )
+ TARGET_LINK_LIBRARIES(AlignedTimeseriesSessionExample
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ )
+ TARGET_LINK_LIBRARIES(TableModelSessionExample
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ )
+ TARGET_LINK_LIBRARIES(MultiSvrNodeClient
+ iotdb_session
+ "${CMAKE_SOURCE_DIR}/thrift/lib/Release/thriftmd.lib"
+ )
+ ENDIF()
ELSE()
- TARGET_LINK_LIBRARIES(SessionExample
- iotdb_session
- pthread
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(AlignedTimeseriesSessionExample
- iotdb_session
- pthread
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(TableModelSessionExample
- iotdb_session
- pthread
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(MultiSvrNodeClient
- iotdb_session
- pthread
- OpenSSL::SSL
- OpenSSL::Crypto
- )
-ENDIF()
\ No newline at end of file
+ IF(WITH_SSL)
+ TARGET_LINK_LIBRARIES(SessionExample
+ iotdb_session
+ pthread
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(AlignedTimeseriesSessionExample
+ iotdb_session
+ pthread
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(TableModelSessionExample
+ iotdb_session
+ pthread
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(MultiSvrNodeClient
+ iotdb_session
+ pthread
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ ELSE()
+ TARGET_LINK_LIBRARIES(SessionExample
+ iotdb_session
+ pthread
+ )
+ TARGET_LINK_LIBRARIES(AlignedTimeseriesSessionExample
+ iotdb_session
+ pthread
+ )
+ TARGET_LINK_LIBRARIES(TableModelSessionExample
+ iotdb_session
+ pthread
+ )
+ TARGET_LINK_LIBRARIES(MultiSvrNodeClient
+ iotdb_session
+ pthread
+ )
+ ENDIF()
+ENDIF()
diff --git a/iotdb-client/client-cpp/pom.xml b/iotdb-client/client-cpp/pom.xml
index c307c651fba8b..bf0f92204e41e 100644
--- a/iotdb-client/client-cpp/pom.xml
+++ b/iotdb-client/client-cpp/pom.xml
@@ -38,6 +38,7 @@
${project.build.directory}/dependency/cmake/
${project.build.directory}/thrift/bin/${thrift.executable}
${ctest.skip.tests}
+ false
@@ -217,6 +218,7 @@
${project.build.directory}/build/main
+
@@ -233,6 +235,7 @@
${project.build.directory}/build/test
+
diff --git a/iotdb-client/client-cpp/src/main/CMakeLists.txt b/iotdb-client/client-cpp/src/main/CMakeLists.txt
index 7945cd887d37f..8119c3830f4b7 100644
--- a/iotdb-client/client-cpp/src/main/CMakeLists.txt
+++ b/iotdb-client/client-cpp/src/main/CMakeLists.txt
@@ -26,13 +26,23 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -g -O2 ")
# Add Thrift include directory
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/../../thrift/include)
-# Find OpenSSL Library
-FIND_PACKAGE(OpenSSL REQUIRED)
-IF(OpenSSL_FOUND)
- MESSAGE(STATUS "OpenSSL found: ${OPENSSL_VERSION}")
- INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
+# =========================
+# SSL option (default OFF)
+# =========================
+option(WITH_SSL "Build with SSL support" OFF)
+
+IF(WITH_SSL)
+ FIND_PACKAGE(OpenSSL REQUIRED)
+ IF(OpenSSL_FOUND)
+ MESSAGE(STATUS "OpenSSL found: ${OPENSSL_VERSION}")
+ INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
+ ADD_DEFINITIONS(-DWITH_SSL=1)
+ ELSE()
+ MESSAGE(FATAL_ERROR "OpenSSL not found, but WITH_SSL is enabled")
+ ENDIF()
ELSE()
- MESSAGE(FATAL_ERROR "OpenSSL not found")
+ MESSAGE(STATUS "Building without SSL support")
+ ADD_DEFINITIONS(-DWITH_SSL=0)
ENDIF()
# Add Boost include path for MacOS
@@ -51,8 +61,8 @@ ELSE()
ENDIF()
IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND NOT MSVC)
- add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
- add_link_options(-fsanitize=address)
+ #add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
+ #add_link_options(-fsanitize=address)
ENDIF()
# Add the generated source files to the sources for the library.
@@ -63,10 +73,20 @@ ELSE()
ADD_LIBRARY(iotdb_session SHARED ${SESSION_SRCS})
ENDIF()
-# Link with Thrift static library
-target_link_libraries(iotdb_session
- PUBLIC
- OpenSSL::SSL
- OpenSSL::Crypto
- ${THRIFT_STATIC_LIB}
-)
+# =========================
+# Link libraries (SSL optional)
+# =========================
+IF(WITH_SSL)
+ target_link_libraries(iotdb_session
+ PUBLIC
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ ${THRIFT_STATIC_LIB}
+ )
+ELSE()
+ target_link_libraries(iotdb_session
+ PUBLIC
+ ${THRIFT_STATIC_LIB}
+ )
+ENDIF()
+
diff --git a/iotdb-client/client-cpp/src/main/SessionConnection.cpp b/iotdb-client/client-cpp/src/main/SessionConnection.cpp
index 0ab22cc79a600..7ed903d24fb41 100644
--- a/iotdb-client/client-cpp/src/main/SessionConnection.cpp
+++ b/iotdb-client/client-cpp/src/main/SessionConnection.cpp
@@ -100,11 +100,17 @@ SessionConnection::~SessionConnection() {
void SessionConnection::init(const TEndPoint& endpoint, bool useSSL, const std::string& trustCertFilePath) {
if (useSSL) {
+#if WITH_SSL
socketFactory_->loadTrustedCertificates(trustCertFilePath.c_str());
socketFactory_->authenticate(false);
auto sslSocket = socketFactory_->createSocket(endPoint.ip, endPoint.port);
sslSocket->setConnTimeout(connectionTimeoutInMs);
transport = std::make_shared(sslSocket);
+#else
+ throw IoTDBException("SSL/TLS support is not enabled in this build. "
+ "Please rebuild with -DWITH_SSL=ON flag "
+ "or use non-SSL connection.");
+#endif
} else {
auto socket = std::make_shared(endPoint.ip, endPoint.port);
socket->setConnTimeout(connectionTimeoutInMs);
diff --git a/iotdb-client/client-cpp/src/main/SessionConnection.h b/iotdb-client/client-cpp/src/main/SessionConnection.h
index 297898ca9a233..a4ef7a7d64c48 100644
--- a/iotdb-client/client-cpp/src/main/SessionConnection.h
+++ b/iotdb-client/client-cpp/src/main/SessionConnection.h
@@ -23,7 +23,10 @@
#include
#include
#include
+#if WITH_SSL
#include
+#endif
+
#include "IClientRPCService.h"
#include "common_types.h"
#include "NodesSupplier.h"
@@ -179,9 +182,10 @@ class SessionConnection : public std::enable_shared_from_this
TSStatus insertTabletsInternal(TSInsertTabletsReq request);
TSStatus deleteDataInternal(TSDeleteDataReq request);
-
+#if WITH_SSL
std::shared_ptr socketFactory_ =
std::make_shared();
+#endif
std::shared_ptr transport;
std::shared_ptr client;
Session* session;
diff --git a/iotdb-client/client-cpp/src/main/ThriftConnection.cpp b/iotdb-client/client-cpp/src/main/ThriftConnection.cpp
index 2cb52bed6075b..3a7989a5e7654 100644
--- a/iotdb-client/client-cpp/src/main/ThriftConnection.cpp
+++ b/iotdb-client/client-cpp/src/main/ThriftConnection.cpp
@@ -69,11 +69,17 @@ void ThriftConnection::init(const std::string& username,
const std::string& zoneId,
const std::string& version) {
if (useSSL) {
+#if WITH_SSL
socketFactory_->loadTrustedCertificates(trustCertFilePath.c_str());
socketFactory_->authenticate(false);
auto sslSocket = socketFactory_->createSocket(endPoint_.ip, endPoint_.port);
sslSocket->setConnTimeout(connectionTimeoutInMs_);
transport_ = std::make_shared(sslSocket);
+#else
+ throw IoTDBException("SSL/TLS support is not enabled in this build. "
+ "Please rebuild with -DWITH_SSL=ON flag "
+ "or use non-SSL connection.");
+#endif
} else {
auto socket = std::make_shared(endPoint_.ip, endPoint_.port);
socket->setConnTimeout(connectionTimeoutInMs_);
diff --git a/iotdb-client/client-cpp/src/main/ThriftConnection.h b/iotdb-client/client-cpp/src/main/ThriftConnection.h
index a308c95e3a202..6dae68357fdbc 100644
--- a/iotdb-client/client-cpp/src/main/ThriftConnection.h
+++ b/iotdb-client/client-cpp/src/main/ThriftConnection.h
@@ -20,7 +20,9 @@
#define IOTDB_THRIFTCONNECTION_H
#include
+#if WITH_SSL
#include
+#endif
#include "IClientRPCService.h"
class SessionDataSet;
@@ -60,8 +62,10 @@ class ThriftConnection {
int connectionTimeoutInMs_;
int fetchSize_;
+#if WITH_SSL
std::shared_ptr socketFactory_ =
std::make_shared();
+#endif
std::shared_ptr transport_;
std::shared_ptr client_;
int64_t sessionId_{};
diff --git a/iotdb-client/client-cpp/src/test/CMakeLists.txt b/iotdb-client/client-cpp/src/test/CMakeLists.txt
index ab225f8efb9f5..0a830b05fcd5b 100644
--- a/iotdb-client/client-cpp/src/test/CMakeLists.txt
+++ b/iotdb-client/client-cpp/src/test/CMakeLists.txt
@@ -25,13 +25,23 @@ SET(TARGET_NAME_RELATIONAL session_relational_tests)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -g -O2")
ENABLE_TESTING()
-# OpenSSL
-FIND_PACKAGE(OpenSSL REQUIRED)
-IF(OpenSSL_FOUND)
- MESSAGE(STATUS "OpenSSL found: ${OPENSSL_VERSION}")
- INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
+# =========================
+# SSL option (default OFF)
+# =========================
+option(WITH_SSL "Build with SSL support" OFF)
+
+IF(WITH_SSL)
+ FIND_PACKAGE(OpenSSL REQUIRED)
+ IF(OpenSSL_FOUND)
+ MESSAGE(STATUS "OpenSSL found: ${OPENSSL_VERSION}")
+ INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
+ ADD_DEFINITIONS(-DWITH_SSL=1)
+ ELSE()
+ MESSAGE(FATAL_ERROR "OpenSSL not found, but WITH_SSL is enabled")
+ ENDIF()
ELSE()
- MESSAGE(FATAL_ERROR "OpenSSL not found")
+ MESSAGE(STATUS "Building without SSL support")
+ ADD_DEFINITIONS(-DWITH_SSL=0)
ENDIF()
# Add Boost include path for MacOS
@@ -66,31 +76,53 @@ ADD_EXECUTABLE(${TARGET_NAME_RELATIONAL} main_Relational.cpp cpp/sessionRelation
# Link with shared library iotdb_session and pthread
IF(MSVC)
- TARGET_LINK_LIBRARIES(${TARGET_NAME}
- iotdb_session
- ${THRIFT_STATIC_LIB}
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(${TARGET_NAME_RELATIONAL}
- iotdb_session
- ${THRIFT_STATIC_LIB}
- OpenSSL::SSL
- OpenSSL::Crypto
- )
+ IF(WITH_SSL)
+ TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ iotdb_session
+ ${THRIFT_STATIC_LIB}
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(${TARGET_NAME_RELATIONAL}
+ iotdb_session
+ ${THRIFT_STATIC_LIB}
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ ELSE()
+ TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ iotdb_session
+ ${THRIFT_STATIC_LIB}
+ )
+ TARGET_LINK_LIBRARIES(${TARGET_NAME_RELATIONAL}
+ iotdb_session
+ ${THRIFT_STATIC_LIB}
+ )
+ ENDIF()
ELSE()
- TARGET_LINK_LIBRARIES(${TARGET_NAME}
- iotdb_session
- pthread
- OpenSSL::SSL
- OpenSSL::Crypto
- )
- TARGET_LINK_LIBRARIES(${TARGET_NAME_RELATIONAL}
- iotdb_session
- pthread
- OpenSSL::SSL
- OpenSSL::Crypto
- )
+ IF(WITH_SSL)
+ TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ iotdb_session
+ pthread
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ TARGET_LINK_LIBRARIES(${TARGET_NAME_RELATIONAL}
+ iotdb_session
+ pthread
+ OpenSSL::SSL
+ OpenSSL::Crypto
+ )
+ ELSE()
+ TARGET_LINK_LIBRARIES(${TARGET_NAME}
+ iotdb_session
+ pthread
+ )
+ TARGET_LINK_LIBRARIES(${TARGET_NAME_RELATIONAL}
+ iotdb_session
+ pthread
+ )
+ ENDIF()
ENDIF()
# Add Catch2 include directory
From 00d29b5bae74f9a091d7f6a3acc0560c61bb2d44 Mon Sep 17 00:00:00 2001
From: 761417898 <761417898@qq.com>
Date: Tue, 24 Mar 2026 12:27:04 +0800
Subject: [PATCH 2/2] session c
---
iotdb-client/client-cpp/src/main/SessionC.cpp | 1417 +++++++++++++++++
iotdb-client/client-cpp/src/main/SessionC.h | 440 +++++
.../client-cpp/src/test/CMakeLists.txt | 88 +-
.../client-cpp/src/test/cpp/sessionCIT.cpp | 429 +++++
.../src/test/cpp/sessionCRelationalIT.cpp | 291 ++++
iotdb-client/client-cpp/src/test/main_c.cpp | 45 +
.../client-cpp/src/test/main_c_Relational.cpp | 44 +
7 files changed, 2711 insertions(+), 43 deletions(-)
create mode 100644 iotdb-client/client-cpp/src/main/SessionC.cpp
create mode 100644 iotdb-client/client-cpp/src/main/SessionC.h
create mode 100644 iotdb-client/client-cpp/src/test/cpp/sessionCIT.cpp
create mode 100644 iotdb-client/client-cpp/src/test/cpp/sessionCRelationalIT.cpp
create mode 100644 iotdb-client/client-cpp/src/test/main_c.cpp
create mode 100644 iotdb-client/client-cpp/src/test/main_c_Relational.cpp
diff --git a/iotdb-client/client-cpp/src/main/SessionC.cpp b/iotdb-client/client-cpp/src/main/SessionC.cpp
new file mode 100644
index 0000000000000..1c502b0fac93f
--- /dev/null
+++ b/iotdb-client/client-cpp/src/main/SessionC.cpp
@@ -0,0 +1,1417 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "SessionC.h"
+#include "Session.h"
+#include "TableSession.h"
+#include "TableSessionBuilder.h"
+#include "SessionBuilder.h"
+#include "SessionDataSet.h"
+
+#include
+#include
+#include
+#include