Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions pulsar-client-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# under the License.
#

cmake_minimum_required(VERSION 3.4)
cmake_minimum_required(VERSION 3.4)
project (pulsar-cpp)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules")

Expand All @@ -35,6 +35,9 @@ MESSAGE(STATUS "BUILD_TESTS: " ${BUILD_TESTS})
option(BUILD_PYTHON_WRAPPER "Build Pulsar Python wrapper" ON)
MESSAGE(STATUS "BUILD_PYTHON_WRAPPER: " ${BUILD_PYTHON_WRAPPER})

option(BUILD_PERF_TOOLS "Build Pulsar CLI perf producer/consumer" OFF)
MESSAGE(STATUS "BUILD_PERF_TOOLS: " ${BUILD_PERF_TOOLS})

option(LINK_STATIC "Link against static libraries" OFF)
MESSAGE(STATUS "LINK_STATIC: " ${LINK_STATIC})

Expand Down Expand Up @@ -155,7 +158,6 @@ endif (LINK_STATIC)


find_package(Boost)
set(BOOST_COMPONENTS program_options regex)

if (NOT Boost_VERSION_MAJOR OR
(Boost_VERSION_MAJOR EQUAL 1 AND Boost_VERSION_MINOR LESS 69)
Expand All @@ -168,6 +170,19 @@ if (MSVC)
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} date_time)
endif()

if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
# GCC 4.8.2 implementation of std::regex is buggy
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} regex)
set(CMAKE_CXX_FLAGS " -DPULSAR_USE_BOOST_REGEX")
MESSAGE(STATUS "Using Boost::Regex")
else()
MESSAGE(STATUS "Using std::regex")
endif()

if(BUILD_PERF_TOOLS)
set(BOOST_COMPONENTS ${BOOST_COMPONENTS} program_options)
endif()

find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})

if (BUILD_PYTHON_WRAPPER)
Expand Down Expand Up @@ -286,7 +301,7 @@ if (NOT MSVC)
)
else()
set(COMMON_LIBS
${COMMON_LIBS}
${COMMON_LIBS}
wldap32.lib
Normaliz.lib)
endif()
Expand Down Expand Up @@ -331,7 +346,9 @@ set(CLIENT_LIBS
)

add_subdirectory(lib)
add_subdirectory(perf)
if(BUILD_PERF_TOOLS)
add_subdirectory(perf)
endif(BUILD_PERF_TOOLS)
add_subdirectory(examples)

if (BUILD_TESTS)
Expand Down
19 changes: 16 additions & 3 deletions pulsar-client-cpp/lib/NamedEntity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,21 @@
*/
#include "NamedEntity.h"

const boost::regex NamedEntity::pattern = boost::regex("^[-=:.\\w]*$");

bool NamedEntity::checkName(const std::string& name) {
return boost::regex_match(name, pattern) ? true : false;
for (char c : name) {
switch (c) {
case '=':
case ':':
case ' ':
case '!':
case '\t':
case '\r':
case '\n':
return false;
default:
break;
}
}

return true;
}
9 changes: 2 additions & 7 deletions pulsar-client-cpp/lib/NamedEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
#ifndef _PULSAR_NAMED_ENTITY_HEADER_
#define _PULSAR_NAMED_ENTITY_HEADER_
#pragma once

#include <boost/regex.hpp>
#include <string>

class NamedEntity {
private:
static const boost::regex pattern;

public:
static bool checkName(const std::string& name);
};
#endif
11 changes: 7 additions & 4 deletions pulsar-client-cpp/lib/PartitionedConsumerImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ ConsumerConfiguration PartitionedConsumerImpl::getSinglePartitionConsumerConfig(
config.setBrokerConsumerStatsCacheTimeInMs(conf_.getBrokerConsumerStatsCacheTimeInMs());

const auto shared_this = const_cast<PartitionedConsumerImpl*>(this)->shared_from_this();
config.setMessageListener(std::bind(&PartitionedConsumerImpl::messageReceived, shared_this, _1, _2));
config.setMessageListener(std::bind(&PartitionedConsumerImpl::messageReceived, shared_this,
std::placeholders::_1, std::placeholders::_2));

// Apply total limit of receiver queue size across partitions
// NOTE: if it's called by handleGetPartitions(), the queue size of new internal consumers may be smaller
Expand All @@ -250,8 +251,9 @@ ConsumerImplPtr PartitionedConsumerImpl::newInternalConsumer(unsigned int partit
internalListenerExecutor_, true, Partitioned);

const auto shared_this = const_cast<PartitionedConsumerImpl*>(this)->shared_from_this();
consumer->getConsumerCreatedFuture().addListener(std::bind(
&PartitionedConsumerImpl::handleSinglePartitionConsumerCreated, shared_this, _1, _2, partition));
consumer->getConsumerCreatedFuture().addListener(
std::bind(&PartitionedConsumerImpl::handleSinglePartitionConsumerCreated, shared_this,
std::placeholders::_1, std::placeholders::_2, partition));
consumer->setPartitionIndex(partition);

LOG_DEBUG("Creating Consumer for single Partition - " << topicPartitionName << "SubName - "
Expand Down Expand Up @@ -573,7 +575,8 @@ void PartitionedConsumerImpl::runPartitionUpdateTask() {
void PartitionedConsumerImpl::getPartitionMetadata() {
using namespace std::placeholders;
lookupServicePtr_->getPartitionMetadataAsync(topicName_)
.addListener(std::bind(&PartitionedConsumerImpl::handleGetPartitions, shared_from_this(), _1, _2));
.addListener(std::bind(&PartitionedConsumerImpl::handleGetPartitions, shared_from_this(),
std::placeholders::_1, std::placeholders::_2));
}

void PartitionedConsumerImpl::handleGetPartitions(Result result,
Expand Down
17 changes: 13 additions & 4 deletions pulsar-client-cpp/lib/Url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,18 @@
*/
#include "Url.h"

#include <boost/regex.hpp>
#include <map>

#include <sstream>

#ifdef PULSAR_USE_BOOST_REGEX
#include <boost/regex.hpp>
#define PULSAR_REGEX_NAMESPACE boost
#else
#include <regex>
#define PULSAR_REGEX_NAMESPACE std
#endif

namespace pulsar {

static const std::map<std::string, int> initDefaultPortsMap() {
Expand All @@ -39,14 +48,14 @@ static const std::map<std::string, int>& defaultPortsMap() {

bool Url::parse(const std::string& urlStr, Url& url) {
std::vector<std::string> values;
static const boost::regex expression(
static const PULSAR_REGEX_NAMESPACE::regex expression(
// proto host port
"^(\?:([^:/\?#]+)://)\?(\\w+[^/\?#:]*)(\?::(\\d+))\?"
// path file parameters
"(/\?(\?:[^\?#/]*/)*)\?([^\?#]*)\?(\\\?(.*))\?");

boost::cmatch groups;
if (!boost::regex_match(urlStr.c_str(), groups, expression)) {
PULSAR_REGEX_NAMESPACE::cmatch groups;
if (!PULSAR_REGEX_NAMESPACE::regex_match(urlStr.c_str(), groups, expression)) {
// Invalid url
return false;
}
Expand Down
10 changes: 0 additions & 10 deletions pulsar-client-cpp/lib/auth/AuthAthenz.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@
*/
#include <lib/auth/AuthAthenz.h>

#include <string.h>
#include <time.h>

#include <openssl/sha.h>
#include <openssl/rsa.h>
#include <openssl/ec.h>
#include <openssl/pem.h>

#include <curl/curl.h>

#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
namespace ptree = boost::property_tree;
Expand Down
21 changes: 19 additions & 2 deletions pulsar-client-cpp/lib/auth/athenz/ZTSClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@
#include <boost/property_tree/ptree.hpp>
namespace ptree = boost::property_tree;

#include <boost/regex.hpp>
#include <boost/xpressive/xpressive.hpp>
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/transform_width.hpp>

#include <mutex>

#ifdef PULSAR_USE_BOOST_REGEX
#include <boost/regex.hpp>
#else
#include <regex>
#endif

DECLARE_LOG_OBJECT()

namespace pulsar {
Expand Down Expand Up @@ -360,15 +365,27 @@ const std::string ZTSClient::getHeader() const { return roleHeader_; }
PrivateKeyUri ZTSClient::parseUri(const char *uri) {
PrivateKeyUri uriSt;
// scheme mediatype[;base64] path file

#ifdef PULSAR_USE_BOOST_REGEX
static const boost::regex expression(
"^(\?:([^:/\?#]+):)(\?:([;/\\-\\w]*),)\?(/\?(\?:[^\?#/]*/)*)\?([^\?#]*)");
boost::cmatch groups;
if (boost::regex_match(uri, groups, expression)) {
uriSt.scheme = groups.str(1);
uriSt.mediaTypeAndEncodingType = groups.str(2);
uriSt.data = groups.str(4);
uriSt.path = groups.str(3) + groups.str(4);
}
#else // !PULSAR_USE_BOOST_REGEX
static const std::regex expression(
R"(^(?:([A-Za-z]+):)(?:([/\w\-]+;\w+),([=\w]+))?(?:\/\/)?(\/[^?#]+)?)");
std::cmatch groups;
if (std::regex_match(uri, groups, expression)) {
uriSt.scheme = groups.str(1);
uriSt.mediaTypeAndEncodingType = groups.str(2);
uriSt.data = groups.str(3);
uriSt.path = groups.str(4);
}
#endif // PULSAR_USE_BOOST_REGEX
return uriSt;
}
} // namespace pulsar
9 changes: 0 additions & 9 deletions pulsar-client-cpp/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ if (APPLE)
${Boost_PYTHON27-MT_LIBRARY_RELEASE}
${Boost_PYTHON37-MT_LIBRARY_RELEASE}
${Boost_PYTHON38-MT_LIBRARY_RELEASE})

if (LINK_STATIC)
# When linking statically on MacOS, include also libicu since it's now required by boost::regex
find_library(ICU_DATA REQUIRED NAMES libicudata.a PATHS /usr/local/opt/icu4c/lib)
find_library(ICU_I18N REQUIRED NAMES libicui18n.a PATHS /usr/local/opt/icu4c/lib)
find_library(ICU_UUC REQUIRED NAMES libicuuc.a PATHS /usr/local/opt/icu4c/lib)

set(ICU_LIBS ${ICU_DATA} ${ICU_I18N} ${ICU_UUC})
endif ()
endif()

message(STATUS "Using Boost Python libs: ${PYTHON_WRAPPER_LIBS}")
Expand Down
2 changes: 0 additions & 2 deletions pulsar-client-cpp/tests/ConsumerConfigurationTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
#include <pulsar/Client.h>
#include <gtest/gtest.h>
#include <boost/date_time/posix_time/ptime.hpp>
#include <boost/bind.hpp>
#include <lib/LogUtils.h>

DECLARE_LOG_OBJECT()
Expand Down
2 changes: 1 addition & 1 deletion pulsar-client-cpp/tests/ZTSClientTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TEST(ZTSClientTest, testZTSClient) {
{
PrivateKeyUri uri = ZTSClientWrapper::parseUri("file:///path/to/private.key");
ASSERT_EQ("file", uri.scheme);
ASSERT_EQ("///path/to/private.key", uri.path);
ASSERT_EQ("/path/to/private.key", uri.path);
}

{
Expand Down