From 14c94c0df9cf04d28124b94d7bdccc5cfa03ab15 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 3 Dec 2014 13:46:28 -0800 Subject: [PATCH] add session->zap_enabled() checks mechanism != NULL, or NULL + non-empty zap_domain --- src/session_base.cpp | 8 ++++++++ src/session_base.hpp | 1 + src/stream_engine.cpp | 6 +++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/session_base.cpp b/src/session_base.cpp index 44942ec3..46dc401e 100644 --- a/src/session_base.cpp +++ b/src/session_base.cpp @@ -331,6 +331,14 @@ int zmq::session_base_t::zap_connect () return 0; } +bool zmq::session_base_t::zap_enabled () +{ + return ( + options.mechanism != ZMQ_NULL || + (options.mechanism == ZMQ_NULL && options.zap_domain.length() > 0) + ); +} + void zmq::session_base_t::process_attach (i_engine *engine_) { zmq_assert (engine_ != NULL); diff --git a/src/session_base.hpp b/src/session_base.hpp index 8491827f..74858f3b 100644 --- a/src/session_base.hpp +++ b/src/session_base.hpp @@ -69,6 +69,7 @@ namespace zmq int push_msg (msg_t *msg_); int zap_connect (); + bool zap_enabled (); // Fetches a message. Returns 0 if successful; -1 otherwise. // The caller is responsible for freeing the message when no diff --git a/src/stream_engine.cpp b/src/stream_engine.cpp index 28148bcc..21763d2c 100644 --- a/src/stream_engine.cpp +++ b/src/stream_engine.cpp @@ -534,7 +534,7 @@ bool zmq::stream_engine_t::handshake () // Is the peer using ZMTP/1.0 with no revision number? // If so, we send and receive rest of identity message if (greeting_recv [0] != 0xff || !(greeting_recv [9] & 0x01)) { - if (session->zap_connect () == 0) { + if (session->zap_enabled ()) { // reject ZMTP 1.0 connections if ZAP is enabled error (protocol_error); return false; @@ -581,7 +581,7 @@ bool zmq::stream_engine_t::handshake () } else if (greeting_recv [revision_pos] == ZMTP_1_0) { - if (session->zap_connect () == 0) { + if (session->zap_enabled ()) { // reject ZMTP 1.0 connections if ZAP is enabled error (protocol_error); return false; @@ -597,7 +597,7 @@ bool zmq::stream_engine_t::handshake () } else if (greeting_recv [revision_pos] == ZMTP_2_0) { - if (session->zap_connect () == 0) { + if (session->zap_enabled ()) { // reject ZMTP 2.0 connections if ZAP is enabled error (protocol_error); return false;