Commit a61db18e authored by Luca Boccassi's avatar Luca Boccassi

Problem: WSS LAST_ENDPOINT returns WS transport

Solution: add wss_address_t subclass of ws_address_t to override the
to_string method
parent c711941e
......@@ -103,12 +103,14 @@ option(WITH_NSS "Use NSS instead of builtin sha1" OFF)
if (NOT DISABLE_WS)
list(APPEND sources
${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_decoder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_encoder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_engine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_listener.cpp
${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_decoder.hpp
${CMAKE_CURRENT_SOURCE_DIR}/src/ws_encoder.hpp
......
......@@ -286,6 +286,8 @@ if HAVE_WS
src_libzmq_la_SOURCES += \
src/ws_address.cpp \
src/ws_address.hpp \
src/wss_address.cpp \
src/wss_address.hpp \
src/ws_connecter.cpp \
src/ws_connecter.hpp \
src/ws_decoder.cpp \
......
......@@ -46,6 +46,7 @@ class ctx_t;
class tcp_address_t;
class udp_address_t;
class ws_address_t;
class wss_address_t;
#if defined ZMQ_HAVE_IPC
class ipc_address_t;
#endif
......@@ -99,6 +100,7 @@ struct address_t
udp_address_t *udp_addr;
#ifdef ZMQ_HAVE_WS
ws_address_t *ws_addr;
wss_address_t *wss_addr;
#endif
#if defined ZMQ_HAVE_IPC
ipc_address_t *ipc_addr;
......
......@@ -55,6 +55,7 @@
#include "tipc_listener.hpp"
#include "tcp_connecter.hpp"
#include "ws_address.hpp"
#include "wss_address.hpp"
#include "io_thread.hpp"
#include "session_base.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_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 if (protocol == protocol_name::ws) {
#endif
paddr->resolved.ws_addr = new (std::nothrow) ws_address_t ();
alloc_assert (paddr->resolved.ws_addr);
rc = paddr->resolved.ws_addr->resolve (address.c_str (), false,
options.ipv6);
{
paddr->resolved.ws_addr = new (std::nothrow) ws_address_t ();
alloc_assert (paddr->resolved.ws_addr);
rc = paddr->resolved.ws_addr->resolve (address.c_str (), false,
options.ipv6);
}
if (rc != 0) {
LIBZMQ_DELETE (paddr);
return -1;
......
......@@ -65,8 +65,10 @@ class ws_address_t
const char *host () const;
const char *path () const;
private:
protected:
ip_addr_t _address;
private:
std::string _host;
std::string _path;
};
......
......@@ -39,6 +39,7 @@
#include "tcp.hpp"
#include "address.hpp"
#include "ws_address.hpp"
#include "wss_address.hpp"
#include "session_base.hpp"
#include "ws_engine.hpp"
......@@ -118,7 +119,12 @@ void zmq::ws_connecter_t::out_event ()
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_)
......
......@@ -42,6 +42,7 @@
#include "socket_base.hpp"
#include "address.hpp"
#include "ws_engine.hpp"
#include "wss_address.hpp"
#include "session_base.hpp"
#ifdef ZMQ_HAVE_WSS
......@@ -123,7 +124,10 @@ void zmq::ws_listener_t::in_event ()
std::string zmq::ws_listener_t::get_socket_name (zmq::fd_t fd_,
socket_end_t socket_end_) const
{
return zmq::get_socket_name<ws_address_t> (fd_, socket_end_);
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_);
}
int zmq::ws_listener_t::create_socket (const char *addr_)
......
/*
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;
}
/*
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment