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