Update ccapi to 7.9.3 (compatible w/ new boost)
This commit is contained in:
1 parent
bd7ccb5f44
commit
9fa7a9898e
117 files changed
+9016
-11255
No files matched your search
@@ -1,114 +1,61 @@
|
||||
#ifndef INCLUDE_CCAPI_CPP_CCAPI_WS_CONNECTION_H_
|
||||
#define INCLUDE_CCAPI_CPP_CCAPI_WS_CONNECTION_H_
|
||||
#ifdef CCAPI_LEGACY_USE_WEBSOCKETPP
|
||||
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
#include "ccapi_cpp/ccapi_logger.h"
|
||||
#include "ccapi_cpp/ccapi_subscription.h"
|
||||
namespace wspp = websocketpp;
|
||||
|
||||
namespace ccapi {
|
||||
|
||||
/**
|
||||
* This class represents a TCP socket connection for the websocket API.
|
||||
*/
|
||||
class WsConnection CCAPI_FINAL {
|
||||
class WsConnection {
|
||||
public:
|
||||
WsConnection(std::string url, std::string group, std::vector<Subscription> subscriptionList, std::map<std::string, std::string> credential)
|
||||
: url(url), group(group), subscriptionList(subscriptionList), credential(credential) {
|
||||
this->assignDummyId();
|
||||
}
|
||||
WsConnection() {}
|
||||
void assignDummyId() {
|
||||
this->id = this->url + "||" + this->group + "||" + ccapi::toString(this->subscriptionList) + "||" + ccapi::toString(this->credential);
|
||||
this->hdl.reset();
|
||||
}
|
||||
std::string toString() const {
|
||||
WsConnection(const WsConnection&) = delete;
|
||||
WsConnection& operator=(const WsConnection&) = delete;
|
||||
|
||||
WsConnection(const std::string& url, const std::string& group, const std::vector<Subscription>& subscriptionList,
|
||||
const std::map<std::string, std::string>& credential, const std::string& proxyUrl = "")
|
||||
: url(url), group(group), subscriptionList(subscriptionList), credential(credential), proxyUrl(proxyUrl) {
|
||||
std::map<std::string, std::string> shortCredential;
|
||||
for (const auto& x : credential) {
|
||||
shortCredential.insert(std::make_pair(x.first, UtilString::firstNCharacter(x.second, CCAPI_CREDENTIAL_DISPLAY_LENGTH)));
|
||||
}
|
||||
std::string output = "WsConnection [id = " + id + ", url = " + url + ", group = " + group + ", subscriptionList = " + ccapi::toString(subscriptionList) +
|
||||
", credential = " + ccapi::toString(shortCredential) + ", status = " + statusToString(status) +
|
||||
", headers = " + ccapi::toString(headers) + "]";
|
||||
return output;
|
||||
}
|
||||
enum class Status {
|
||||
UNKNOWN,
|
||||
CONNECTING,
|
||||
OPEN,
|
||||
FAILED,
|
||||
CLOSING,
|
||||
CLOSED,
|
||||
};
|
||||
static std::string statusToString(Status status) {
|
||||
std::string output;
|
||||
switch (status) {
|
||||
case Status::UNKNOWN:
|
||||
output = "UNKNOWN";
|
||||
break;
|
||||
case Status::CONNECTING:
|
||||
output = "CONNECTING";
|
||||
break;
|
||||
case Status::OPEN:
|
||||
output = "OPEN";
|
||||
break;
|
||||
case Status::FAILED:
|
||||
output = "FAILED";
|
||||
break;
|
||||
case Status::CLOSING:
|
||||
output = "CLOSING";
|
||||
break;
|
||||
case Status::CLOSED:
|
||||
output = "CLOSED";
|
||||
break;
|
||||
default:
|
||||
CCAPI_LOGGER_FATAL(CCAPI_UNSUPPORTED_VALUE);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
std::string id;
|
||||
std::string url;
|
||||
std::string group;
|
||||
std::vector<Subscription> subscriptionList;
|
||||
Status status{Status::UNKNOWN};
|
||||
wspp::connection_hdl hdl = wspp::lib::weak_ptr<void>();
|
||||
std::map<std::string, std::string> headers;
|
||||
std::map<std::string, std::string> credential;
|
||||
};
|
||||
} /* namespace ccapi */
|
||||
#else
|
||||
#include <string>
|
||||
|
||||
#include "ccapi_cpp/ccapi_logger.h"
|
||||
#include "ccapi_cpp/ccapi_subscription.h"
|
||||
namespace ccapi {
|
||||
/**
|
||||
* This class represents a TCP socket connection for the websocket API.
|
||||
*/
|
||||
class WsConnection CCAPI_FINAL {
|
||||
public:
|
||||
WsConnection(std::string url, std::string group, std::vector<Subscription> subscriptionList, std::map<std::string, std::string> credential,
|
||||
std::shared_ptr<beast::websocket::stream<beast::ssl_stream<beast::tcp_stream> > > streamPtr)
|
||||
: url(url), group(group), subscriptionList(subscriptionList), credential(credential), streamPtr(streamPtr) {
|
||||
this->id = this->url + "||" + this->group + "||" + ccapi::toString(this->subscriptionList) + "||" + ccapi::toString(this->credential);
|
||||
this->longId = this->url + "||" + this->group + "||" + ccapi::toString(this->subscriptionList) + "||" + ccapi::toString(shortCredential);
|
||||
this->id = UtilAlgorithm::shortBase62Hash(this->longId);
|
||||
this->correlationIdList.reserve(subscriptionList.size());
|
||||
std::transform(subscriptionList.cbegin(), subscriptionList.cend(), std::back_inserter(this->correlationIdList),
|
||||
[](Subscription subscription) { return subscription.getCorrelationId(); });
|
||||
this->setUrlParts();
|
||||
}
|
||||
|
||||
WsConnection() {}
|
||||
|
||||
std::string toString() const {
|
||||
std::map<std::string, std::string> shortCredential;
|
||||
for (const auto& x : credential) {
|
||||
shortCredential.insert(std::make_pair(x.first, UtilString::firstNCharacter(x.second, CCAPI_CREDENTIAL_DISPLAY_LENGTH)));
|
||||
}
|
||||
std::ostringstream oss;
|
||||
oss << streamPtr;
|
||||
std::string output = "WsConnection [id = " + id + ", url = " + url + ", group = " + group + ", subscriptionList = " + ccapi::toString(subscriptionList) +
|
||||
", credential = " + ccapi::toString(shortCredential) + ", status = " + statusToString(status) +
|
||||
", headers = " + ccapi::toString(headers) + ", streamPtr = " + oss.str() + ", remoteCloseCode = " + std::to_string(remoteCloseCode) +
|
||||
std::visit(
|
||||
[&oss](auto&& streamPtr) {
|
||||
if (streamPtr) {
|
||||
oss << streamPtr.get();
|
||||
} else {
|
||||
oss << "nullptr";
|
||||
}
|
||||
},
|
||||
streamPtr);
|
||||
std::string output = "WsConnection [longId = " + longId + ", id = " + id + ", url = " + url + ", group = " + group +
|
||||
", subscriptionList = " + ccapi::toString(subscriptionList) + ", credential = " + ccapi::toString(shortCredential) +
|
||||
", proxyUrl = " + proxyUrl + ", status = " + statusToString(status) + ", headers = " + ccapi::toString(headers) +
|
||||
", streamPtr = " + oss.str() + ", remoteCloseCode = " + std::to_string(remoteCloseCode) +
|
||||
", remoteCloseReason = " + std::string(remoteCloseReason.reason.c_str()) +
|
||||
", hostHttpHeaderValue = " + ccapi::toString(hostHttpHeaderValue) + ", path = " + ccapi::toString(path) +
|
||||
", host = " + ccapi::toString(host) + ", port = " + ccapi::toString(port) + "]";
|
||||
", host = " + ccapi::toString(host) + ", port = " + ccapi::toString(port) + ", isSecure = " + ccapi::toString(isSecure) + "]";
|
||||
return output;
|
||||
}
|
||||
enum class Status {
|
||||
@@ -119,6 +66,7 @@ class WsConnection CCAPI_FINAL {
|
||||
CLOSING,
|
||||
CLOSED,
|
||||
};
|
||||
|
||||
static std::string statusToString(Status status) {
|
||||
std::string output;
|
||||
switch (status) {
|
||||
@@ -145,11 +93,14 @@ class WsConnection CCAPI_FINAL {
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
std::string getUrl() const { return url; }
|
||||
|
||||
void setUrl(const std::string& url) {
|
||||
this->url = url;
|
||||
this->setUrlParts();
|
||||
}
|
||||
|
||||
void setUrlParts() {
|
||||
auto splitted1 = UtilString::split(url, "://");
|
||||
if (splitted1.size() >= 2) {
|
||||
@@ -175,31 +126,43 @@ class WsConnection CCAPI_FINAL {
|
||||
this->port = CCAPI_HTTP_PORT_DEFAULT;
|
||||
}
|
||||
}
|
||||
if (splitted1.at(0) == "https" || splitted1.at(0) == "wss") {
|
||||
this->isSecure = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void appendUrlPart(const std::string& urlPart) {
|
||||
this->url += urlPart;
|
||||
this->setUrlParts();
|
||||
}
|
||||
|
||||
std::string longId;
|
||||
std::string id;
|
||||
std::string url;
|
||||
std::string group;
|
||||
std::vector<Subscription> subscriptionList;
|
||||
std::vector<std::string> correlationIdList;
|
||||
Status status{Status::UNKNOWN};
|
||||
std::map<std::string, std::string> headers;
|
||||
std::map<std::string, std::string> credential;
|
||||
std::shared_ptr<beast::websocket::stream<beast::ssl_stream<beast::tcp_stream> > > streamPtr;
|
||||
std::string proxyUrl;
|
||||
std::variant<std::shared_ptr<beast::websocket::stream<beast::ssl_stream<beast::tcp_stream>>>, std::shared_ptr<beast::websocket::stream<beast::tcp_stream>>>
|
||||
streamPtr;
|
||||
beast::websocket::close_code remoteCloseCode{};
|
||||
beast::websocket::close_reason remoteCloseReason{};
|
||||
std::string hostHttpHeaderValue;
|
||||
std::string path;
|
||||
std::string host;
|
||||
std::string port;
|
||||
#ifndef CCAPI_EXPOSE_INTERNAL
|
||||
private:
|
||||
#endif
|
||||
std::string url;
|
||||
|
||||
beast::flat_buffer readMessageBuffer;
|
||||
std::array<char, CCAPI_WEBSOCKET_WRITE_BUFFER_SIZE> writeMessageBuffer;
|
||||
size_t writeMessageBufferWrittenLength{};
|
||||
std::vector<size_t> writeMessageBufferBoundary;
|
||||
bool isSecure{};
|
||||
};
|
||||
|
||||
} /* namespace ccapi */
|
||||
#endif
|
||||
|
||||
#endif // INCLUDE_CCAPI_CPP_CCAPI_WS_CONNECTION_H_
|
||||
Reference in new issue
Block a user