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_,
mechanism_t (options_),
session (session_),
peer_address (peer_address_),
zap_client (session, peer_address, options),
ready_command_sent (false),
error_command_sent (false),
ready_command_received (false),
......@@ -193,71 +194,7 @@ zmq::mechanism_t::status_t zmq::null_mechanism_t::status () const
int zmq::null_mechanism_t::send_zap_request ()
{
int rc;
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;
return zap_client.send_zap_request ("NULL", 4, NULL, 0);
}
int zmq::null_mechanism_t::receive_and_process_zap_reply ()
......
......@@ -32,6 +32,7 @@
#include "mechanism.hpp"
#include "options.hpp"
#include "zap_client.hpp"
namespace zmq
{
......@@ -62,6 +63,8 @@ namespace zmq
const std::string peer_address;
zap_client_t zap_client;
bool ready_command_sent;
bool error_command_sent;
bool ready_command_received;
......
......@@ -111,12 +111,15 @@ int zap_client_t::send_zap_request (const char *mechanism,
return close_and_return (&msg, -1);
// Credentials frame
rc = msg.init_size (credentials_size);
errno_assert (rc == 0);
memcpy (msg.data (), credentials, credentials_size);
rc = session->write_zap_msg (&msg);
if (rc != 0)
return close_and_return (&msg, -1);
// Skip if credential is NULL
if (credentials) {
rc = msg.init_size (credentials_size);
errno_assert (rc == 0);
memcpy (msg.data (), credentials, credentials_size);
rc = session->write_zap_msg (&msg);
if (rc != 0)
return close_and_return (&msg, -1);
}
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