14 zmq::plain_server_t::plain_server_t (session_base_t *session_,
17 mechanism_base_t (session_,
options_),
18 zap_client_common_handshake_t (
19 session_, peer_address_,
options_, sending_welcome)
30 zmq::plain_server_t::~plain_server_t ()
34 int zmq::plain_server_t::next_handshake_command (msg_t *msg_)
40 produce_welcome (msg_);
41 state = waiting_for_initiate;
58 int zmq::plain_server_t::process_handshake_command (msg_t *msg_)
63 case waiting_for_hello:
64 rc = process_hello (msg_);
66 case waiting_for_initiate:
67 rc = process_initiate (msg_);
71 session->get_socket ()->event_handshake_failed_protocol (
86 int zmq::plain_server_t::process_hello (msg_t *msg_)
88 int rc = check_basic_command_structure (msg_);
92 const char *ptr =
static_cast<char *
> (msg_->data ());
93 size_t bytes_left = msg_->size ();
97 session->get_socket ()->event_handshake_failed_protocol (
105 if (bytes_left < 1) {
107 session->get_socket ()->event_handshake_failed_protocol (
108 session->get_endpoint (),
113 const uint8_t username_length = *ptr++;
114 bytes_left -=
sizeof (username_length);
116 if (bytes_left < username_length) {
118 session->get_socket ()->event_handshake_failed_protocol (
119 session->get_endpoint (),
125 ptr += username_length;
126 bytes_left -= username_length;
127 if (bytes_left < 1) {
129 session->get_socket ()->event_handshake_failed_protocol (
130 session->get_endpoint (),
136 const uint8_t password_length = *ptr++;
137 bytes_left -=
sizeof (password_length);
138 if (bytes_left != password_length) {
141 session->get_socket ()->event_handshake_failed_protocol (
142 session->get_endpoint (),
151 rc = session->zap_connect ();
153 session->get_socket ()->event_handshake_failed_no_detail (
154 session->get_endpoint (),
EFAULT);
158 send_zap_request (username, password);
159 state = waiting_for_zap_reply;
165 return receive_and_process_zap_reply () == -1 ? -1 : 0;
168 void zmq::plain_server_t::produce_welcome (msg_t *msg_)
175 int zmq::plain_server_t::process_initiate (msg_t *msg_)
177 const unsigned char *ptr =
static_cast<unsigned char *
> (msg_->data ());
178 const size_t bytes_left = msg_->size ();
182 session->get_socket ()->event_handshake_failed_protocol (
190 state = sending_ready;
194 void zmq::plain_server_t::produce_ready (msg_t *msg_)
const
199 void zmq::plain_server_t::produce_error (msg_t *msg_)
const
201 const char expected_status_code_len = 3;
203 ==
static_cast<size_t> (expected_status_code_len));
204 const size_t status_code_len_size =
sizeof (expected_status_code_len);
206 + expected_status_code_len);
208 char *msg_data =
static_cast<char *
> (msg_->data ());
212 status_code.c_str (), status_code.length ());
215 void zmq::plain_server_t::send_zap_request (
const std::string &username_,
218 const uint8_t *credentials[] = {
219 reinterpret_cast<const uint8_t *
> (username_.c_str ()),
220 reinterpret_cast<const uint8_t *
> (password_.c_str ())};
221 size_t credentials_sizes[] = {username_.size (), password_.size ()};
222 const char plain_mechanism_name[] =
"PLAIN";
223 zap_client_t::send_zap_request (
224 plain_mechanism_name,
sizeof (plain_mechanism_name) - 1, credentials,
225 credentials_sizes,
sizeof (credentials) /
sizeof (credentials[0]));