Commit 34999d50 authored by Simon Giesecke's avatar Simon Giesecke

Problem: s_send(more) can be replaced by safer send_string_expect_success

Solution: remove s_send(more) and replace all uses
parent af4fa22f
......@@ -61,18 +61,18 @@ static void zap_handler (void *handler_)
TEST_ASSERT_EQUAL_STRING ("1.0", version);
TEST_ASSERT_EQUAL_STRING ("NULL", mechanism);
s_sendmore (handler_, version);
s_sendmore (handler_, sequence);
send_string_expect_success (handler_, version, ZMQ_SNDMORE);
send_string_expect_success (handler_, sequence, ZMQ_SNDMORE);
if (streq (domain, "DOMAIN")) {
s_sendmore (handler_, "200");
s_sendmore (handler_, "OK");
s_sendmore (handler_, "anonymous");
send_string_expect_success (handler_, "200", ZMQ_SNDMORE);
send_string_expect_success (handler_, "OK", ZMQ_SNDMORE);
send_string_expect_success (handler_, "anonymous", ZMQ_SNDMORE);
zmq_send (handler_, metadata, sizeof (metadata), 0);
} else {
s_sendmore (handler_, "400");
s_sendmore (handler_, "BAD DOMAIN");
s_sendmore (handler_, "");
s_send (handler_, "");
send_string_expect_success (handler_, "400", ZMQ_SNDMORE);
send_string_expect_success (handler_, "BAD DOMAIN", ZMQ_SNDMORE);
send_string_expect_success (handler_, "", ZMQ_SNDMORE);
send_string_expect_success (handler_, "", 0);
}
free (version);
free (sequence);
......@@ -104,7 +104,7 @@ void test_metadata ()
bind_loopback_ipv4 (server, my_endpoint, sizeof (my_endpoint));
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, my_endpoint));
s_send (client, "This is a message");
send_string_expect_success (client, "This is a message", 0);
zmq_msg_t msg;
zmq_msg_init (&msg);
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, server, 0));
......
......@@ -234,7 +234,7 @@ void server_task (void * /*unused_*/)
}
for (int i = 0; i < QT_CLIENTS; ++i) {
TEST_ASSERT_SUCCESS_ERRNO (s_send (endpoint_receivers[i], my_endpoint));
send_string_expect_success (endpoint_receivers[i], my_endpoint, 0);
}
// Connect backend to frontend via a proxy
......
......@@ -48,8 +48,7 @@ void server_task (void * /*unused_*/)
void *control = zmq_socket (get_test_context (), ZMQ_REQ);
TEST_ASSERT_NOT_NULL (control);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (control, "inproc://control"));
TEST_ASSERT_GREATER_THAN_INT (
0, TEST_ASSERT_SUCCESS_ERRNO (s_send (control, my_endpoint)));
send_string_expect_success (control, my_endpoint, 0);
// Use rep as both frontend and backend
TEST_ASSERT_SUCCESS_ERRNO (zmq_proxy_steerable (rep, rep, NULL, control));
......
......@@ -57,8 +57,7 @@ void server_task (void * /*unused_*/)
void *control = zmq_socket (get_test_context (), ZMQ_REQ);
TEST_ASSERT_NOT_NULL (control);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (control, "inproc://control"));
TEST_ASSERT_GREATER_THAN_INT (
0, TEST_ASSERT_SUCCESS_ERRNO (s_send (control, my_endpoint)));
send_string_expect_success (control, my_endpoint, 0);
// Connect backend to frontend via a proxy
TEST_ASSERT_SUCCESS_ERRNO (
......
......@@ -44,7 +44,8 @@ void test_scatter_gather_multipart_fails ()
zmq_connect (gather, "inproc://test-scatter-gather"));
// Should fail, multipart is not supported
TEST_ASSERT_FAILURE_ERRNO (EINVAL, s_sendmore (scatter, "1"));
TEST_ASSERT_FAILURE_ERRNO (EINVAL,
zmq_send_const (scatter, "1", 1, ZMQ_SNDMORE));
test_context_socket_close (scatter);
test_context_socket_close (gather);
......
......@@ -82,20 +82,20 @@ static void zap_handler (void *handler_)
TEST_ASSERT_EQUAL_STRING ("1.0", version);
TEST_ASSERT_EQUAL_STRING ("GSSAPI", mechanism);
s_sendmore (handler_, version);
s_sendmore (handler_, sequence);
send_string_expect_success (handler_, version, ZMQ_SNDMORE);
send_string_expect_success (handler_, sequence, ZMQ_SNDMORE);
if (!zap_deny_all) {
s_sendmore (handler_, "200");
s_sendmore (handler_, "OK");
s_sendmore (handler_, "anonymous");
s_send (handler_, "");
send_string_expect_success (handler_, "200", ZMQ_SNDMORE);
send_string_expect_success (handler_, "OK", ZMQ_SNDMORE);
send_string_expect_success (handler_, "anonymous", ZMQ_SNDMORE);
send_string_expect_success (handler_, "", 0);
//fprintf (stderr, "ALLOW %s\n", principal);
} else {
s_sendmore (handler_, "400");
s_sendmore (handler_, "Denied");
s_sendmore (handler_, "");
s_send (handler_, "");
send_string_expect_success (handler_, "400", ZMQ_SNDMORE);
send_string_expect_success (handler_, "Denied", ZMQ_SNDMORE);
send_string_expect_success (handler_, "", ZMQ_SNDMORE);
send_string_expect_success (handler_, "", 0);
//fprintf (stderr, "DENY %s\n", principal);
}
free (version);
......
......@@ -61,18 +61,18 @@ static void zap_handler (void *handler_)
TEST_ASSERT_EQUAL_STRING ("1.0", version);
TEST_ASSERT_EQUAL_STRING ("NULL", mechanism);
s_sendmore (handler_, version);
s_sendmore (handler_, sequence);
send_string_expect_success (handler_, version, ZMQ_SNDMORE);
send_string_expect_success (handler_, sequence, ZMQ_SNDMORE);
if (streq (domain, "TEST")) {
s_sendmore (handler_, "200");
s_sendmore (handler_, "OK");
s_sendmore (handler_, "anonymous");
s_send (handler_, "");
send_string_expect_success (handler_, "200", ZMQ_SNDMORE);
send_string_expect_success (handler_, "OK", ZMQ_SNDMORE);
send_string_expect_success (handler_, "anonymous", ZMQ_SNDMORE);
send_string_expect_success (handler_, "", 0);
} else {
s_sendmore (handler_, "400");
s_sendmore (handler_, "BAD DOMAIN");
s_sendmore (handler_, "");
s_send (handler_, "");
send_string_expect_success (handler_, "400", ZMQ_SNDMORE);
send_string_expect_success (handler_, "BAD DOMAIN", ZMQ_SNDMORE);
send_string_expect_success (handler_, "", ZMQ_SNDMORE);
send_string_expect_success (handler_, "", 0);
}
free (version);
free (sequence);
......
......@@ -64,18 +64,19 @@ static void zap_handler (void *zap_)
TEST_ASSERT_EQUAL_STRING ("PLAIN", mechanism);
TEST_ASSERT_EQUAL_STRING ("IDENT", routing_id);
s_sendmore (zap_, version);
s_sendmore (zap_, sequence);
send_string_expect_success (zap_, version, ZMQ_SNDMORE);
send_string_expect_success (zap_, sequence, ZMQ_SNDMORE);
if (streq (username, "admin") && streq (password, "password")) {
s_sendmore (zap_, "200");
s_sendmore (zap_, "OK");
s_sendmore (zap_, "anonymous");
s_send (zap_, "");
send_string_expect_success (zap_, "200", ZMQ_SNDMORE);
send_string_expect_success (zap_, "OK", ZMQ_SNDMORE);
send_string_expect_success (zap_, "anonymous", ZMQ_SNDMORE);
send_string_expect_success (zap_, "", 0);
} else {
s_sendmore (zap_, "400");
s_sendmore (zap_, "Invalid username or password");
s_sendmore (zap_, "");
s_send (zap_, "");
send_string_expect_success (zap_, "400", ZMQ_SNDMORE);
send_string_expect_success (zap_, "Invalid username or password",
ZMQ_SNDMORE);
send_string_expect_success (zap_, "", ZMQ_SNDMORE);
send_string_expect_success (zap_, "", 0);
}
free (version);
free (sequence);
......
......@@ -149,18 +149,6 @@ char *s_recv (void *socket_)
return strdup (buffer);
}
int s_send (void *socket_, const char *string_)
{
int size = zmq_send (socket_, string_, strlen (string_), 0);
return size;
}
int s_sendmore (void *socket_, const char *string_)
{
int size = zmq_send (socket_, string_, strlen (string_), ZMQ_SNDMORE);
return size;
}
void s_send_seq (void *socket_, ...)
{
va_list ap;
......
......@@ -111,12 +111,6 @@ void expect_bounce_fail (void *server_, void *client_);
// is being terminated.
char *s_recv (void *socket_);
// Convert C string to 0MQ string and send to socket
int s_send (void *socket_, const char *string_);
// Sends string as 0MQ string, as multipart non-terminal
int s_sendmore (void *socket_, const char *string_);
bool streq (const char *lhs, const char *rhs);
bool strneq (const char *lhs, const char *rhs);
......
......@@ -203,12 +203,15 @@ void zap_handler_generic (zap_protocol_t zap_protocol_,
TEST_ASSERT_EQUAL_STRING ("1.0", version);
TEST_ASSERT_EQUAL_STRING (expected_routing_id_, routing_id);
s_sendmore (handler, zap_protocol_ == zap_wrong_version
? "invalid_version"
: version);
s_sendmore (handler, zap_protocol_ == zap_wrong_request_id
? "invalid_request_id"
: sequence);
send_string_expect_success (
handler,
zap_protocol_ == zap_wrong_version ? "invalid_version" : version,
ZMQ_SNDMORE);
send_string_expect_success (handler,
zap_protocol_ == zap_wrong_request_id
? "invalid_request_id"
: sequence,
ZMQ_SNDMORE);
if (authentication_succeeded) {
const char *status_code;
......@@ -225,20 +228,21 @@ void zap_handler_generic (zap_protocol_t zap_protocol_,
default:
status_code = "200";
}
s_sendmore (handler, status_code);
s_sendmore (handler, "OK");
s_sendmore (handler, "anonymous");
send_string_expect_success (handler, status_code, ZMQ_SNDMORE);
send_string_expect_success (handler, "OK", ZMQ_SNDMORE);
send_string_expect_success (handler, "anonymous", ZMQ_SNDMORE);
if (zap_protocol_ == zap_too_many_parts) {
s_sendmore (handler, "");
send_string_expect_success (handler, "", ZMQ_SNDMORE);
}
if (zap_protocol_ != zap_do_not_send)
s_send (handler, "");
send_string_expect_success (handler, "", 0);
} else {
s_sendmore (handler, "400");
s_sendmore (handler, "Invalid client public key");
s_sendmore (handler, "");
send_string_expect_success (handler, "400", ZMQ_SNDMORE);
send_string_expect_success (handler, "Invalid client public key",
ZMQ_SNDMORE);
send_string_expect_success (handler, "", ZMQ_SNDMORE);
if (zap_protocol_ != zap_do_not_send)
s_send (handler, "");
send_string_expect_success (handler, "", 0);
}
free (version);
free (sequence);
......
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