mirror of
https://github.com/zeromq/libzmq.git
synced 2025-11-08 14:56:14 +01:00
Problem: WSS LAST_ENDPOINT returns WS transport
Solution: add wss_address_t subclass of ws_address_t to override the to_string method
This commit is contained in:
@@ -103,12 +103,14 @@ option(WITH_NSS "Use NSS instead of builtin sha1" OFF)
|
|||||||
if (NOT DISABLE_WS)
|
if (NOT DISABLE_WS)
|
||||||
list(APPEND sources
|
list(APPEND sources
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_address.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_address.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/wss_address.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_connecter.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_connecter.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_decoder.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_decoder.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_encoder.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_encoder.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_engine.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_engine.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_listener.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_listener.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_address.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_address.hpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/wss_address.hpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_connecter.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_connecter.hpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_decoder.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_decoder.hpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_encoder.hpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_encoder.hpp
|
||||||
|
|||||||
@@ -286,6 +286,8 @@ if HAVE_WS
|
|||||||
src_libzmq_la_SOURCES += \
|
src_libzmq_la_SOURCES += \
|
||||||
src/ws_address.cpp \
|
src/ws_address.cpp \
|
||||||
src/ws_address.hpp \
|
src/ws_address.hpp \
|
||||||
|
src/wss_address.cpp \
|
||||||
|
src/wss_address.hpp \
|
||||||
src/ws_connecter.cpp \
|
src/ws_connecter.cpp \
|
||||||
src/ws_connecter.hpp \
|
src/ws_connecter.hpp \
|
||||||
src/ws_decoder.cpp \
|
src/ws_decoder.cpp \
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class ctx_t;
|
|||||||
class tcp_address_t;
|
class tcp_address_t;
|
||||||
class udp_address_t;
|
class udp_address_t;
|
||||||
class ws_address_t;
|
class ws_address_t;
|
||||||
|
class wss_address_t;
|
||||||
#if defined ZMQ_HAVE_IPC
|
#if defined ZMQ_HAVE_IPC
|
||||||
class ipc_address_t;
|
class ipc_address_t;
|
||||||
#endif
|
#endif
|
||||||
@@ -99,6 +100,7 @@ struct address_t
|
|||||||
udp_address_t *udp_addr;
|
udp_address_t *udp_addr;
|
||||||
#ifdef ZMQ_HAVE_WS
|
#ifdef ZMQ_HAVE_WS
|
||||||
ws_address_t *ws_addr;
|
ws_address_t *ws_addr;
|
||||||
|
wss_address_t *wss_addr;
|
||||||
#endif
|
#endif
|
||||||
#if defined ZMQ_HAVE_IPC
|
#if defined ZMQ_HAVE_IPC
|
||||||
ipc_address_t *ipc_addr;
|
ipc_address_t *ipc_addr;
|
||||||
|
|||||||
@@ -55,6 +55,7 @@
|
|||||||
#include "tipc_listener.hpp"
|
#include "tipc_listener.hpp"
|
||||||
#include "tcp_connecter.hpp"
|
#include "tcp_connecter.hpp"
|
||||||
#include "ws_address.hpp"
|
#include "ws_address.hpp"
|
||||||
|
#include "wss_address.hpp"
|
||||||
#include "io_thread.hpp"
|
#include "io_thread.hpp"
|
||||||
#include "session_base.hpp"
|
#include "session_base.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
@@ -904,13 +905,22 @@ int zmq::socket_base_t::connect (const char *endpoint_uri_)
|
|||||||
#ifdef ZMQ_HAVE_WS
|
#ifdef ZMQ_HAVE_WS
|
||||||
#ifdef ZMQ_HAVE_WSS
|
#ifdef ZMQ_HAVE_WSS
|
||||||
else if (protocol == protocol_name::ws || protocol == protocol_name::wss) {
|
else if (protocol == protocol_name::ws || protocol == protocol_name::wss) {
|
||||||
|
if (protocol == protocol_name::wss) {
|
||||||
|
paddr->resolved.wss_addr = new (std::nothrow) wss_address_t ();
|
||||||
|
alloc_assert (paddr->resolved.wss_addr);
|
||||||
|
rc = paddr->resolved.wss_addr->resolve (address.c_str (), false,
|
||||||
|
options.ipv6);
|
||||||
|
} else
|
||||||
#else
|
#else
|
||||||
else if (protocol == protocol_name::ws) {
|
else if (protocol == protocol_name::ws) {
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
paddr->resolved.ws_addr = new (std::nothrow) ws_address_t ();
|
paddr->resolved.ws_addr = new (std::nothrow) ws_address_t ();
|
||||||
alloc_assert (paddr->resolved.ws_addr);
|
alloc_assert (paddr->resolved.ws_addr);
|
||||||
rc = paddr->resolved.ws_addr->resolve (address.c_str (), false,
|
rc = paddr->resolved.ws_addr->resolve (address.c_str (), false,
|
||||||
options.ipv6);
|
options.ipv6);
|
||||||
|
}
|
||||||
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
LIBZMQ_DELETE (paddr);
|
LIBZMQ_DELETE (paddr);
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -65,8 +65,10 @@ class ws_address_t
|
|||||||
const char *host () const;
|
const char *host () const;
|
||||||
const char *path () const;
|
const char *path () const;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
ip_addr_t _address;
|
ip_addr_t _address;
|
||||||
|
|
||||||
|
private:
|
||||||
std::string _host;
|
std::string _host;
|
||||||
std::string _path;
|
std::string _path;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
#include "tcp.hpp"
|
#include "tcp.hpp"
|
||||||
#include "address.hpp"
|
#include "address.hpp"
|
||||||
#include "ws_address.hpp"
|
#include "ws_address.hpp"
|
||||||
|
#include "wss_address.hpp"
|
||||||
#include "session_base.hpp"
|
#include "session_base.hpp"
|
||||||
#include "ws_engine.hpp"
|
#include "ws_engine.hpp"
|
||||||
|
|
||||||
@@ -118,7 +119,12 @@ void zmq::ws_connecter_t::out_event ()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
create_engine (fd, get_socket_name<ws_address_t> (fd, socket_end_local));
|
if (_wss)
|
||||||
|
create_engine (fd,
|
||||||
|
get_socket_name<wss_address_t> (fd, socket_end_local));
|
||||||
|
else
|
||||||
|
create_engine (fd,
|
||||||
|
get_socket_name<ws_address_t> (fd, socket_end_local));
|
||||||
}
|
}
|
||||||
|
|
||||||
void zmq::ws_connecter_t::timer_event (int id_)
|
void zmq::ws_connecter_t::timer_event (int id_)
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
#include "socket_base.hpp"
|
#include "socket_base.hpp"
|
||||||
#include "address.hpp"
|
#include "address.hpp"
|
||||||
#include "ws_engine.hpp"
|
#include "ws_engine.hpp"
|
||||||
|
#include "wss_address.hpp"
|
||||||
#include "session_base.hpp"
|
#include "session_base.hpp"
|
||||||
|
|
||||||
#ifdef ZMQ_HAVE_WSS
|
#ifdef ZMQ_HAVE_WSS
|
||||||
@@ -123,6 +124,9 @@ void zmq::ws_listener_t::in_event ()
|
|||||||
std::string zmq::ws_listener_t::get_socket_name (zmq::fd_t fd_,
|
std::string zmq::ws_listener_t::get_socket_name (zmq::fd_t fd_,
|
||||||
socket_end_t socket_end_) const
|
socket_end_t socket_end_) const
|
||||||
{
|
{
|
||||||
|
if (_wss)
|
||||||
|
return zmq::get_socket_name<wss_address_t> (fd_, socket_end_);
|
||||||
|
else
|
||||||
return zmq::get_socket_name<ws_address_t> (fd_, socket_end_);
|
return zmq::get_socket_name<ws_address_t> (fd_, socket_end_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
53
src/wss_address.cpp
Normal file
53
src/wss_address.cpp
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019 Contributors as noted in the AUTHORS file
|
||||||
|
|
||||||
|
This file is part of libzmq, the ZeroMQ core engine in C++.
|
||||||
|
|
||||||
|
libzmq is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
||||||
|
by the Free Software Foundation; either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
As a special exception, the Contributors give you permission to link
|
||||||
|
this library with independent modules to produce an executable,
|
||||||
|
regardless of the license terms of these independent modules, and to
|
||||||
|
copy and distribute the resulting executable under terms of your choice,
|
||||||
|
provided that you also meet, for each linked independent module, the
|
||||||
|
terms and conditions of the license of that module. An independent
|
||||||
|
module is a module which is not derived from or based on this library.
|
||||||
|
If you modify this library, you must extend this exception to your
|
||||||
|
version of the library.
|
||||||
|
|
||||||
|
libzmq is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "precompiled.hpp"
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "wss_address.hpp"
|
||||||
|
|
||||||
|
zmq::wss_address_t::wss_address_t () : ws_address_t ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
zmq::wss_address_t::wss_address_t (const sockaddr *sa_, socklen_t sa_len_) :
|
||||||
|
ws_address_t (sa_, sa_len_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int zmq::wss_address_t::to_string (std::string &addr_) const
|
||||||
|
{
|
||||||
|
std::ostringstream os;
|
||||||
|
os << std::string ("wss://") << host () << std::string (":")
|
||||||
|
<< _address.port ();
|
||||||
|
addr_ = os.str ();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
47
src/wss_address.hpp
Normal file
47
src/wss_address.hpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2019 Contributors as noted in the AUTHORS file
|
||||||
|
|
||||||
|
This file is part of libzmq, the ZeroMQ core engine in C++.
|
||||||
|
|
||||||
|
libzmq is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
||||||
|
by the Free Software Foundation; either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
As a special exception, the Contributors give you permission to link
|
||||||
|
this library with independent modules to produce an executable,
|
||||||
|
regardless of the license terms of these independent modules, and to
|
||||||
|
copy and distribute the resulting executable under terms of your choice,
|
||||||
|
provided that you also meet, for each linked independent module, the
|
||||||
|
terms and conditions of the license of that module. An independent
|
||||||
|
module is a module which is not derived from or based on this library.
|
||||||
|
If you modify this library, you must extend this exception to your
|
||||||
|
version of the library.
|
||||||
|
|
||||||
|
libzmq is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ZMQ_WSS_ADDRESS_HPP_INCLUDED__
|
||||||
|
#define __ZMQ_WSS_ADDRESS_HPP_INCLUDED__
|
||||||
|
|
||||||
|
#include "ws_address.hpp"
|
||||||
|
|
||||||
|
namespace zmq
|
||||||
|
{
|
||||||
|
class wss_address_t : public ws_address_t
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wss_address_t ();
|
||||||
|
wss_address_t (const sockaddr *sa_, socklen_t sa_len_);
|
||||||
|
// The opposite to resolve()
|
||||||
|
int to_string (std::string &addr_) const;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user