Commit b324c66b authored by sigiesec's avatar sigiesec

Problem: null_mechanism duplicates zap_client_t::send_zap_request\nSolution: use…

Problem: null_mechanism duplicates zap_client_t::send_zap_request\nSolution: use zap_client_t::send_zap_request
parent f3884f33
...@@ -45,6 +45,7 @@ zmq::null_mechanism_t::null_mechanism_t (session_base_t *session_, ...@@ -45,6 +45,7 @@ zmq::null_mechanism_t::null_mechanism_t (session_base_t *session_,
mechanism_t (options_), mechanism_t (options_),
session (session_), session (session_),
peer_address (peer_address_), peer_address (peer_address_),
zap_client (session, peer_address, options),
ready_command_sent (false), ready_command_sent (false),
error_command_sent (false), error_command_sent (false),
ready_command_received (false), ready_command_received (false),
...@@ -193,71 +194,7 @@ zmq::mechanism_t::status_t zmq::null_mechanism_t::status () const ...@@ -193,71 +194,7 @@ zmq::mechanism_t::status_t zmq::null_mechanism_t::status () const
int zmq::null_mechanism_t::send_zap_request () int zmq::null_mechanism_t::send_zap_request ()
{ {
int rc; return zap_client.send_zap_request ("NULL", 4, NULL, 0);
msg_t msg;
// Address delimiter frame
rc = msg.init ();
errno_assert (rc == 0);
msg.set_flags (msg_t::more);
rc = session->write_zap_msg (&msg);
if (rc != 0)
return close_and_return (&msg, -1);
// Version frame
rc = msg.init_size (3);
errno_assert (rc == 0);
memcpy (msg.data (), "1.0", 3);
msg.set_flags (msg_t::more);
rc = session->write_zap_msg (&msg);
if (rc != 0)
return close_and_return (&msg, -1);
// Request id frame
rc = msg.init_size (1);
errno_assert (rc == 0);
memcpy (msg.data (), "1", 1);
msg.set_flags (msg_t::more);
rc = session->write_zap_msg (&msg);
if (rc != 0)
return close_and_return (&msg, -1);
// Domain frame
rc = msg.init_size (options.zap_domain.length ());
errno_assert (rc == 0);
memcpy (msg.data (), options.zap_domain.c_str (), options.zap_domain.length ());
msg.set_flags (msg_t::more);
rc = session->write_zap_msg (&msg);
if (rc != 0)
return close_and_return (&msg, -1);
// Address frame
rc = msg.init_size (peer_address.length ());
errno_assert (rc == 0);
memcpy (msg.data (), peer_address.c_str (), peer_address.length ());
msg.set_flags (msg_t::more);
rc = session->write_zap_msg (&msg);
if (rc != 0)
return close_and_return (&msg, -1);
// Identity frame
rc = msg.init_size (options.identity_size);
errno_assert (rc == 0);
memcpy (msg.data (), options.identity, options.identity_size);
msg.set_flags (msg_t::more);
rc = session->write_zap_msg (&msg);
if (rc != 0)
return close_and_return (&msg, -1);
// Mechanism frame
rc = msg.init_size (4);
errno_assert (rc == 0);
memcpy (msg.data (), "NULL", 4);
rc = session->write_zap_msg (&msg);
if (rc != 0)
return close_and_return (&msg, -1);
return 0;
} }
int zmq::null_mechanism_t::receive_and_process_zap_reply () int zmq::null_mechanism_t::receive_and_process_zap_reply ()
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "mechanism.hpp" #include "mechanism.hpp"
#include "options.hpp" #include "options.hpp"
#include "zap_client.hpp"
namespace zmq namespace zmq
{ {
...@@ -62,6 +63,8 @@ namespace zmq ...@@ -62,6 +63,8 @@ namespace zmq
const std::string peer_address; const std::string peer_address;
zap_client_t zap_client;
bool ready_command_sent; bool ready_command_sent;
bool error_command_sent; bool error_command_sent;
bool ready_command_received; bool ready_command_received;
......
...@@ -111,12 +111,15 @@ int zap_client_t::send_zap_request (const char *mechanism, ...@@ -111,12 +111,15 @@ int zap_client_t::send_zap_request (const char *mechanism,
return close_and_return (&msg, -1); return close_and_return (&msg, -1);
// Credentials frame // Credentials frame
rc = msg.init_size (credentials_size); // Skip if credential is NULL
errno_assert (rc == 0); if (credentials) {
memcpy (msg.data (), credentials, credentials_size); rc = msg.init_size (credentials_size);
rc = session->write_zap_msg (&msg); errno_assert (rc == 0);
if (rc != 0) memcpy (msg.data (), credentials, credentials_size);
return close_and_return (&msg, -1); rc = session->write_zap_msg (&msg);
if (rc != 0)
return close_and_return (&msg, -1);
}
return 0; return 0;
} }
......
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