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
1 change: 1 addition & 0 deletions pulsar-client-cpp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# Compiled Dynamic libraries
*.so
lib*.so*
*.dylib
*.dll
*.so.1
Expand Down
10 changes: 9 additions & 1 deletion pulsar-client-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ find_library(CURL_LIBRARY_PATH curl)
find_path(LOG4CXX_INCLUDE_PATH log4cxx/logger.h)
find_path(GTEST_INCLUDE_PATH gtest/gtest.h)

set(ADDITIONAL_LIBRARIES $ENV{PULSAR_ADDITIONAL_LIBRARIES})
link_directories( $ENV{PULSAR_ADDITIONAL_LIBRARY_PATH} )

include_directories(
${CMAKE_SOURCE_DIR}
Expand All @@ -53,13 +55,19 @@ set(COMMON_LIBS
${PROTOBUF_LIBRARIES}
${LOG4CXX_LIBRARY_PATH}
${CURL_LIBRARY_PATH}
${ADDITIONAL_LIBRARIES}
)

link_directories(${CMAKE_BINARY_DIR}/lib)

set(LIB_NAME $ENV{PULSAR_LIBRARY_NAME})
if (NOT LIB_NAME)
set(LIB_NAME pulsar)
endif(NOT LIB_NAME)

set(CLIENT_LIBS
${COMMON_LIBS}
pulsar
${LIB_NAME}
)

add_subdirectory(lib)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,22 @@
* limitations under the License.
*/

#ifndef PULSAR_AUTH_H_
#define PULSAR_AUTH_H_
#ifndef PULSAR_AUTHENTICATION_H_
#define PULSAR_AUTHENTICATION_H_

#include <vector>
#include <string>
#include <map>
#include <boost/shared_ptr.hpp>
#include <pulsar/Result.h>
#include <boost/make_shared.hpp>

#pragma GCC visibility push(default)

namespace pulsar {

#ifdef PULSAR_ENABLE_DEPRECATED_METHOD
// This is deprecated.
enum AuthType {
AuthNone,
AuthYcaV1
};
// This is deprecated.
class AuthData {
public:
virtual ~AuthData();

virtual AuthType getType() const = 0;

virtual Result getAuthData(std::string& authDataContent) const = 0;

protected:
AuthData();
};
typedef boost::shared_ptr<AuthData> AuthDataPtr;
#endif
class ClientConfiguration;
class Authentication;

class AuthenticationDataProvider {
public:
Expand All @@ -64,6 +47,8 @@ namespace pulsar {
};

typedef boost::shared_ptr<AuthenticationDataProvider> AuthenticationDataPtr;
typedef boost::shared_ptr<Authentication> AuthenticationPtr;
typedef std::map<std::string, std::string> ParamMap;

class Authentication {
public:
Expand All @@ -73,30 +58,15 @@ namespace pulsar {
authDataContent = authData_;
return ResultOk;
}
#ifdef PULSAR_ENABLE_DEPRECATED_METHOD
// This is deprecated.
virtual Result getAuthData(std::string& authDataContent) const {
return ResultOk;
}
#endif
protected:
Authentication();
AuthenticationDataPtr authData_;
friend class ClientConfiguration;
};

typedef boost::shared_ptr<Authentication> AuthenticationPtr;
typedef std::map<std::string, std::string> ParamMap;

class Auth {
class AuthFactory {
public:
#ifdef PULSAR_ENABLE_DEPRECATED_METHOD
// This is deprecated.
static AuthDataPtr Disabled();
// This is deprecated.
static AuthDataPtr YcaV1(const std::string& ycaAppId);
#else
static AuthenticationPtr Disabled();
#endif
static AuthenticationPtr create(const std::string& dynamicLibPath);
static AuthenticationPtr create(const std::string& dynamicLibPath, const std::string& authParamsString);
static AuthenticationPtr create(const std::string& dynamicLibPath, ParamMap& params);
Expand All @@ -106,10 +76,9 @@ namespace pulsar {
static std::vector<void *> loadedLibrariesHandles_;
static void release_handles();
};

}
// namespace pulsar

#pragma GCC visibility pop

#endif /* PULSAR_AUTH_H_ */
#endif /* PULSAR_AUTHENTICATION_H_ */
37 changes: 33 additions & 4 deletions pulsar-client-cpp/include/pulsar/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,30 @@
#ifndef PULSAR_CLIENT_HPP_
#define PULSAR_CLIENT_HPP_

#include <pulsar/Auth.h>
#include <pulsar/Authentication.h>
#include <pulsar/Consumer.h>
#include <pulsar/Producer.h>
#include <pulsar/Result.h>
#include <pulsar/Message.h>
#include <pulsar/MessageBuilder.h>

#include <string>

#ifdef PULSAR_ENABLE_DEPRECATED_METHOD
#include<pulsar/Auth.h>
#else
// Deprecated
namespace pulsar {
class AuthData;
typedef boost::shared_ptr<AuthData> AuthDataPtr;
class AuthData {
public:
static AuthenticationPtr getAuthenticationPtr(const AuthDataPtr& authentication) {
AuthenticationPtr ptr;
return ptr;
}
};
}
#endif
#pragma GCC visibility push(default)

class PulsarFriend;
Expand All @@ -44,17 +59,31 @@ class ClientConfiguration {
ClientConfiguration(const ClientConfiguration&);
ClientConfiguration& operator=(const ClientConfiguration&);

/**
* @deprecated
* Set the authentication method to be used with the broker
*
* @param authentication the authentication data to use
*/
ClientConfiguration& setAuthentication(const AuthDataPtr& authentication);

/**
* @deprecated
* @return the authentication data
*/
const AuthData& getAuthentication() const;

/**
* Set the authentication method to be used with the broker
*
* @param authentication the authentication data to use
*/
ClientConfiguration& setAuthentication(const AuthenticationPtr& authentication);
ClientConfiguration& setAuth(const AuthenticationPtr& authentication);

/**
* @return the authentication data
*/
const Authentication& getAuthentication() const;
const Authentication& getAuth() const;

/**
* Set timeout on client operations (subscribe, create producer, close, unsubscribe)
Expand Down
15 changes: 5 additions & 10 deletions pulsar-client-cpp/include/pulsar/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@
#pragma GCC visibility push(default)

namespace pulsar {
namespace proto {
class CommandMessage;
class MessageMetadata;
class SingleMessageMetadata;
}
}

using namespace pulsar;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed using namespace pulsar;


namespace pulsar {
namespace proto {
class CommandMessage;
class MessageMetadata;
class SingleMessageMetadata;
}

class SharedBuffer;
class MessageBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <stdio.h>

#include <pulsar/Auth.h>
#include <pulsar/Authentication.h>
#include <lib/LogUtils.h>

#include <string>
Expand Down Expand Up @@ -102,30 +102,30 @@ namespace pulsar {
};


AuthenticationPtr Auth::Disabled() {
AuthenticationPtr AuthFactory::Disabled() {
ParamMap params;
return AuthDisabled::create(params);
}

AuthenticationPtr Auth::create(const std::string& dynamicLibPath) {
AuthenticationPtr AuthFactory::create(const std::string& dynamicLibPath) {
ParamMap params;
return Auth::create(dynamicLibPath, params);
return AuthFactory::create(dynamicLibPath, params);
}

boost::mutex mutex;
std::vector<void*> Auth::loadedLibrariesHandles_;
bool Auth::isShutdownHookRegistered_ = false;
std::vector<void*> AuthFactory::loadedLibrariesHandles_;
bool AuthFactory::isShutdownHookRegistered_ = false;

void Auth::release_handles() {
void AuthFactory::release_handles() {
boost::lock_guard<boost::mutex> lock(mutex);
for (std::vector<void*>::iterator ite = Auth::loadedLibrariesHandles_.begin(); ite != Auth::loadedLibrariesHandles_.end();
for (std::vector<void*>::iterator ite = AuthFactory::loadedLibrariesHandles_.begin(); ite != AuthFactory::loadedLibrariesHandles_.end();
ite++) {
dlclose(*ite);
}
loadedLibrariesHandles_.clear();
}

AuthenticationPtr Auth::create(const std::string& dynamicLibPath, const std::string& authParamsString) {
AuthenticationPtr AuthFactory::create(const std::string& dynamicLibPath, const std::string& authParamsString) {
ParamMap paramMap;
if(!authParamsString.empty()) {
std::vector<std::string> params;
Expand All @@ -138,15 +138,15 @@ namespace pulsar {
}
}
}
return Auth::create(dynamicLibPath, paramMap);
return AuthFactory::create(dynamicLibPath, paramMap);
}

AuthenticationPtr Auth::create(const std::string& dynamicLibPath, ParamMap& params) {
AuthenticationPtr AuthFactory::create(const std::string& dynamicLibPath, ParamMap& params) {
{
boost::lock_guard<boost::mutex> lock(mutex);
if (!Auth::isShutdownHookRegistered_) {
if (!AuthFactory::isShutdownHookRegistered_) {
atexit(release_handles);
Auth::isShutdownHookRegistered_ = true;
AuthFactory::isShutdownHookRegistered_ = true;
}
}
Authentication *auth = NULL;
Expand Down
2 changes: 1 addition & 1 deletion pulsar-client-cpp/lib/BinaryProtoLookupService.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <iostream>

#include <boost/shared_ptr.hpp>
#include <pulsar/Auth.h>
#include <pulsar/Authentication.h>
#include <pulsar/Result.h>
#include "ConnectionPool.h"
#include "DestinationName.h"
Expand Down
10 changes: 7 additions & 3 deletions pulsar-client-cpp/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@
file(GLOB PULSAR_SOURCES *.cc lz4/*.c checksum/*.cc)

execute_process(COMMAND cat ../pom.xml COMMAND xmllint --format - COMMAND sed "s/xmlns=\".*\"//g" COMMAND xmllint --stream --pattern /project/version --debug - COMMAND grep -A 2 "matches pattern" COMMAND grep text COMMAND sed "s/.* [0-9] //g" OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE PV)

set (CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} -msse4.2 -mpclmul -D_PULSAR_VERSION_=\\\"${PV}\\\"")

add_library(pulsarStatic STATIC ${PULSAR_SOURCES})
add_library(pulsarShared SHARED ${PULSAR_SOURCES})

set_target_properties(pulsarStatic PROPERTIES OUTPUT_NAME pulsar VERSION ${PV})
set_target_properties(pulsarShared PROPERTIES OUTPUT_NAME pulsar VERSION ${PV})
set(LIBRARY_VERSION $ENV{PULSAR_LIBRARY_VERSION})
if (NOT LIBRARY_VERSION)
set(LIBRARY_VERSION ${PV})
endif(NOT LIBRARY_VERSION)

set_target_properties(pulsarStatic PROPERTIES OUTPUT_NAME ${LIB_NAME} VERSION ${LIBRARY_VERSION})
set_target_properties(pulsarShared PROPERTIES OUTPUT_NAME ${LIB_NAME} VERSION ${LIBRARY_VERSION})

target_link_libraries(pulsarStatic ${COMMON_LIBS})
target_link_libraries(pulsarShared ${COMMON_LIBS})
Expand Down
26 changes: 19 additions & 7 deletions pulsar-client-cpp/lib/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ DECLARE_LOG_OBJECT()
namespace pulsar {

struct ClientConfiguration::Impl {
AuthenticationPtr authData;
AuthenticationPtr authenticationPtr;
AuthDataPtr authDataPtr;
int ioThreads;
int operationTimeoutSeconds;
int messageListenerThreads;
Expand All @@ -40,7 +41,7 @@ struct ClientConfiguration::Impl {
bool useTls;
std::string tlsTrustCertsFilePath;
bool tlsAllowInsecureConnection;
Impl() : authData(Auth::Disabled()),
Impl() : authenticationPtr(AuthFactory::Disabled()),
ioThreads(1),
operationTimeoutSeconds(30),
messageListenerThreads(1),
Expand All @@ -66,17 +67,28 @@ ClientConfiguration& ClientConfiguration::operator=(const ClientConfiguration& x
return *this;
}

ClientConfiguration& ClientConfiguration::setAuthentication(const AuthenticationPtr& authentication) {
impl_->authData = authentication;
ClientConfiguration& ClientConfiguration::setAuth(const AuthenticationPtr& authentication) {
impl_->authenticationPtr = authentication;
return *this;
}

const Authentication& ClientConfiguration::getAuthentication() const {
return *impl_->authData;
const Authentication& ClientConfiguration::getAuth() const {
return *impl_->authenticationPtr;
}

ClientConfiguration& ClientConfiguration::setAuthentication(const AuthDataPtr& authentication) {
impl_->authDataPtr = authentication;
impl_->authenticationPtr = AuthData::getAuthenticationPtr(authentication);
return *this;
}

const AuthData& ClientConfiguration::getAuthentication() const {
return *(impl_->authDataPtr);
}


const AuthenticationPtr& ClientConfiguration::getAuthenticationPtr() const {
return impl_->authData;
return impl_->authenticationPtr;
}

ClientConfiguration& ClientConfiguration::setOperationTimeoutSeconds(int timeout) {
Expand Down
2 changes: 1 addition & 1 deletion pulsar-client-cpp/lib/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef LIB_COMMANDS_H_
#define LIB_COMMANDS_H_

#include <pulsar/Auth.h>
#include <pulsar/Authentication.h>
#include <pulsar/Message.h>

#include "PulsarApi.pb.h"
Expand Down
2 changes: 1 addition & 1 deletion pulsar-client-cpp/lib/auth/AuthTls.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef PULSAR_AUTH_TLS_H_
#define PULSAR_AUTH_TLS_H_

#include <pulsar/Auth.h>
#include <pulsar/Authentication.h>
#include <lib/LogUtils.h>
#include <iostream>
#include <string>
Expand Down
Loading