Commit 6b8569d7 authored by Martin Hurton's avatar Martin Hurton

Merge pull request #572 from hintjens/master

Updated ZAP PLAIN request to follow latest draft
parents 210fcbbb 6ff51ee9
...@@ -23,9 +23,10 @@ argument to be sent to the socket referenced by the 'socket' argument. The ...@@ -23,9 +23,10 @@ argument to be sent to the socket referenced by the 'socket' argument. The
'flags' argument is a combination of the flags defined below: 'flags' argument is a combination of the flags defined below:
*ZMQ_DONTWAIT*:: *ZMQ_DONTWAIT*::
Specifies that the operation should be performed in non-blocking mode. If the For socket types (DEALER, PUSH) that block when there are no available peers
message cannot be queued on the 'socket', the _zmq_msg_send()_ function shall (or all peers have full high-water mark), specifies that the operation should
fail with 'errno' set to EAGAIN. be performed in non-blocking mode. If the message cannot be queued on the
'socket', the _zmq_msg_send()_ function shall fail with 'errno' set to EAGAIN.
*ZMQ_SNDMORE*:: *ZMQ_SNDMORE*::
Specifies that the message being sent is a multi-part message, and that further Specifies that the message being sent is a multi-part message, and that further
......
...@@ -19,9 +19,10 @@ referenced by the 'buf' and 'len' arguments. The 'flags' argument is ...@@ -19,9 +19,10 @@ referenced by the 'buf' and 'len' arguments. The 'flags' argument is
a combination of the flags defined below: a combination of the flags defined below:
*ZMQ_DONTWAIT*:: *ZMQ_DONTWAIT*::
Specifies that the operation should be performed in non-blocking mode. If the For socket types (DEALER, PUSH) that block when there are no available peers
message cannot be queued on the 'socket', the _zmq_send()_ function shall (or all peers have full high-water mark), specifies that the operation should
fail with 'errno' set to EAGAIN. be performed in non-blocking mode. If the message cannot be queued on the
'socket', the _zmq_send()_ function shall fail with 'errno' set to EAGAIN.
*ZMQ_SNDMORE*:: *ZMQ_SNDMORE*::
Specifies that the message being sent is a multi-part message, and that further Specifies that the message being sent is a multi-part message, and that further
......
...@@ -19,9 +19,10 @@ argument to be sent to the socket referenced by the 'socket' argument. The ...@@ -19,9 +19,10 @@ argument to be sent to the socket referenced by the 'socket' argument. The
'flags' argument is a combination of the flags defined below: 'flags' argument is a combination of the flags defined below:
*ZMQ_DONTWAIT*:: *ZMQ_DONTWAIT*::
Specifies that the operation should be performed in non-blocking mode. If the For socket types (DEALER, PUSH) that block when there are no available peers
message cannot be queued on the 'socket', the _zmq_sendmsg()_ function shall (or all peers have full high-water mark), specifies that the operation should
fail with 'errno' set to EAGAIN. be performed in non-blocking mode. If the message cannot be queued on the
'socket', the _zmq_sendmsg()_ function shall fail with 'errno' set to EAGAIN.
*ZMQ_SNDMORE*:: *ZMQ_SNDMORE*::
Specifies that the message being sent is a multi-part message, and that further Specifies that the message being sent is a multi-part message, and that further
......
...@@ -71,11 +71,9 @@ sequence of _zmq_send(request)_ and subsequent _zmq_recv(reply)_ calls. Each ...@@ -71,11 +71,9 @@ sequence of _zmq_send(request)_ and subsequent _zmq_recv(reply)_ calls. Each
request sent is round-robined among all _services_, and each reply received is request sent is round-robined among all _services_, and each reply received is
matched with the last issued request. matched with the last issued request.
When a 'ZMQ_REQ' socket enters the 'mute' state due to having reached the If no services are available, then any send operation on the socket shall
high water mark for all _services_, or if there are no _services_ at all, then block until at least one _service_ becomes available. The REQ socket shall
any linkzmq:zmq_send[3] operations on the socket shall block until the not discard messages.
'mute' state ends or at least one _service_ becomes available for sending;
messages are not discarded.
[horizontal] [horizontal]
.Summary of ZMQ_REQ characteristics .Summary of ZMQ_REQ characteristics
...@@ -94,11 +92,7 @@ send replies to a _client_. This socket type allows only an alternating ...@@ -94,11 +92,7 @@ send replies to a _client_. This socket type allows only an alternating
sequence of _zmq_recv(request)_ and subsequent _zmq_send(reply)_ calls. Each sequence of _zmq_recv(request)_ and subsequent _zmq_send(reply)_ calls. Each
request received is fair-queued from among all _clients_, and each reply sent request received is fair-queued from among all _clients_, and each reply sent
is routed to the _client_ that issued the last request. If the original is routed to the _client_ that issued the last request. If the original
requester doesn't exist any more the reply is silently discarded. requester does not exist any more the reply is silently discarded.
When a 'ZMQ_REP' socket enters the 'mute' state due to having reached the
high water mark for a _client_, then any replies sent to the _client_ in
question shall be dropped until the mute state ends.
[horizontal] [horizontal]
.Summary of ZMQ_REP characteristics .Summary of ZMQ_REP characteristics
...@@ -107,7 +101,6 @@ Direction:: Bidirectional ...@@ -107,7 +101,6 @@ Direction:: Bidirectional
Send/receive pattern:: Receive, Send, Receive, Send, ... Send/receive pattern:: Receive, Send, Receive, Send, ...
Incoming routing strategy:: Fair-queued Incoming routing strategy:: Fair-queued
Outgoing routing strategy:: Last peer Outgoing routing strategy:: Last peer
Action in mute state:: Drop
ZMQ_DEALER ZMQ_DEALER
...@@ -126,8 +119,6 @@ When a 'ZMQ_DEALER' socket is connected to a 'ZMQ_REP' socket each message sent ...@@ -126,8 +119,6 @@ When a 'ZMQ_DEALER' socket is connected to a 'ZMQ_REP' socket each message sent
must consist of an empty message part, the _delimiter_, followed by one or more must consist of an empty message part, the _delimiter_, followed by one or more
_body parts_. _body parts_.
Deprecated alias: 'ZMQ_XREQ'.
[horizontal] [horizontal]
.Summary of ZMQ_DEALER characteristics .Summary of ZMQ_DEALER characteristics
Compatible peer sockets:: 'ZMQ_ROUTER', 'ZMQ_REP', 'ZMQ_DEALER' Compatible peer sockets:: 'ZMQ_ROUTER', 'ZMQ_REP', 'ZMQ_DEALER'
...@@ -162,8 +153,6 @@ as seen by the application becomes: one or more _identity_ parts, _delimiter_ ...@@ -162,8 +153,6 @@ as seen by the application becomes: one or more _identity_ parts, _delimiter_
part, one or more _body parts_. When sending replies to a 'ZMQ_REQ' socket the part, one or more _body parts_. When sending replies to a 'ZMQ_REQ' socket the
application must include the _delimiter_ part. application must include the _delimiter_ part.
Deprecated alias: 'ZMQ_XREP'.
[horizontal] [horizontal]
.Summary of ZMQ_ROUTER characteristics .Summary of ZMQ_ROUTER characteristics
Compatible peer sockets:: 'ZMQ_DEALER', 'ZMQ_REQ', 'ZMQ_ROUTER' Compatible peer sockets:: 'ZMQ_DEALER', 'ZMQ_REQ', 'ZMQ_ROUTER'
...@@ -216,7 +205,6 @@ Direction:: Unidirectional ...@@ -216,7 +205,6 @@ Direction:: Unidirectional
Send/receive pattern:: Receive only Send/receive pattern:: Receive only
Incoming routing strategy:: Fair-queued Incoming routing strategy:: Fair-queued
Outgoing routing strategy:: N/A Outgoing routing strategy:: N/A
Action in mute state:: Drop
ZMQ_XPUB ZMQ_XPUB
......
...@@ -262,15 +262,18 @@ int zmq::plain_mechanism_t::process_hello_command (msg_t *msg_) ...@@ -262,15 +262,18 @@ int zmq::plain_mechanism_t::process_hello_command (msg_t *msg_)
rc = session->write_zap_msg (&msg); rc = session->write_zap_msg (&msg);
errno_assert (rc == 0); errno_assert (rc == 0);
// Credentials frame // Username frame
rc = msg.init_size (1 + username_length + 1 + password_length); rc = msg.init_size (username_length);
errno_assert (rc == 0); errno_assert (rc == 0);
char *data_ptr = static_cast <char *> (msg.data ()); memcpy (msg.data (), username.c_str (), username_length);
*data_ptr++ = static_cast <unsigned char> (username_length); msg.set_flags (msg_t::more);
memcpy (data_ptr, username.c_str (), username_length); rc = session->write_zap_msg (&msg);
data_ptr += username_length; errno_assert (rc == 0);
*data_ptr++ = static_cast <unsigned char> (password_length);
memcpy (data_ptr, password.c_str (), password_length); // Password frame
rc = msg.init_size (password_length);
errno_assert (rc == 0);
memcpy (msg.data (), password.c_str (), password_length);
rc = session->write_zap_msg (&msg); rc = session->write_zap_msg (&msg);
errno_assert (rc == 0); errno_assert (rc == 0);
......
...@@ -21,33 +21,12 @@ ...@@ -21,33 +21,12 @@
#include <string.h> #include <string.h>
#include "testutil.hpp" #include "testutil.hpp"
static bool
authenticate (const unsigned char *data, size_t data_length)
{
const char *username = "admin";
const size_t username_length = strlen (username);
const char *password = "password";
const size_t password_length = strlen (password);
if (data_length != 1 + username_length + 1 + password_length)
return false;
if (data [0] != username_length)
return false;
if (memcmp (data + 1, username, username_length))
return false;
if (data [1 + username_length] != password_length)
return false;
if (memcmp (data + 1 + username_length + 1, password, password_length))
return false;
return true;
}
static void * static void *
zap_handler (void *zap) zap_handler (void *zap)
{ {
int rc, more; int rc, more;
size_t optlen; size_t optlen;
zmq_msg_t version, seqno, domain, mechanism, credentials; zmq_msg_t version, seqno, domain, mechanism, username, password;
zmq_msg_t status_code, status_text, user_id; zmq_msg_t status_code, status_text, user_id;
// Version // Version
...@@ -86,17 +65,24 @@ zap_handler (void *zap) ...@@ -86,17 +65,24 @@ zap_handler (void *zap)
rc = zmq_getsockopt (zap, ZMQ_RCVMORE, &more, &optlen); rc = zmq_getsockopt (zap, ZMQ_RCVMORE, &more, &optlen);
assert (rc == 0 && more == 1); assert (rc == 0 && more == 1);
// Credentials // Username
rc = zmq_msg_init (&credentials); rc = zmq_msg_init (&username);
assert (rc == 0);
rc = zmq_msg_recv (&username, zap, 0);
bool username_ok = (rc == 5 && memcmp (zmq_msg_data (&username), "admin", 5) == 0);
optlen = sizeof more;
rc = zmq_getsockopt (zap, ZMQ_RCVMORE, &more, &optlen);
assert (rc == 0 && more == 1);
// Password
rc = zmq_msg_init (&password);
assert (rc == 0); assert (rc == 0);
rc = zmq_msg_recv (&credentials, zap, 0); rc = zmq_msg_recv (&password, zap, 0);
optlen = sizeof more; optlen = sizeof more;
rc = zmq_getsockopt (zap, ZMQ_RCVMORE, &more, &optlen); rc = zmq_getsockopt (zap, ZMQ_RCVMORE, &more, &optlen);
assert (rc == 0 && more == 0); assert (rc == 0 && more == 0);
const bool auth_ok = bool password_ok = (rc == 8 && memcmp (zmq_msg_data (&password), "password", 8) == 0);
authenticate ((unsigned char *) zmq_msg_data (&credentials),
zmq_msg_size (&credentials));
rc = zmq_msg_send (&version, zap, ZMQ_SNDMORE); rc = zmq_msg_send (&version, zap, ZMQ_SNDMORE);
assert (rc == 3); assert (rc == 3);
...@@ -106,7 +92,7 @@ zap_handler (void *zap) ...@@ -106,7 +92,7 @@ zap_handler (void *zap)
rc = zmq_msg_init_size (&status_code, 3); rc = zmq_msg_init_size (&status_code, 3);
assert (rc == 0); assert (rc == 0);
memcpy (zmq_msg_data (&status_code), auth_ok? "200": "400", 3); memcpy (zmq_msg_data (&status_code), username_ok && password_ok? "200": "400", 3);
rc = zmq_msg_send (&status_code, zap, ZMQ_SNDMORE); rc = zmq_msg_send (&status_code, zap, ZMQ_SNDMORE);
assert (rc == 3); assert (rc == 3);
...@@ -126,7 +112,10 @@ zap_handler (void *zap) ...@@ -126,7 +112,10 @@ zap_handler (void *zap)
rc = zmq_msg_close (&mechanism); rc = zmq_msg_close (&mechanism);
assert (rc == 0); assert (rc == 0);
rc = zmq_msg_close (&credentials); rc = zmq_msg_close (&username);
assert (rc == 0);
rc = zmq_msg_close (&password);
assert (rc == 0); assert (rc == 0);
rc = zmq_close (zap); rc = zmq_close (zap);
......
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