Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
93e75fd6
Commit
93e75fd6
authored
May 28, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: Magic numbers "6" and "7" in null_mechanism.cpp
Solution: introduced constants
parent
c05db7f0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
16 deletions
+27
-16
null_mechanism.cpp
src/null_mechanism.cpp
+27
-16
No files found.
src/null_mechanism.cpp
View file @
93e75fd6
...
@@ -38,6 +38,13 @@
...
@@ -38,6 +38,13 @@
#include "session_base.hpp"
#include "session_base.hpp"
#include "null_mechanism.hpp"
#include "null_mechanism.hpp"
const
char
error_command_name
[]
=
"
\5
ERROR"
;
const
size_t
error_command_name_len
=
sizeof
(
error_command_name
)
-
1
;
const
size_t
error_reason_len_size
=
1
;
const
char
ready_command_name
[]
=
"
\5
READY"
;
const
size_t
ready_command_name_len
=
sizeof
(
ready_command_name
)
-
1
;
zmq
::
null_mechanism_t
::
null_mechanism_t
(
session_base_t
*
session_
,
zmq
::
null_mechanism_t
::
null_mechanism_t
(
session_base_t
*
session_
,
const
std
::
string
&
peer_address_
,
const
std
::
string
&
peer_address_
,
const
options_t
&
options_
)
:
const
options_t
&
options_
)
:
...
@@ -95,20 +102,16 @@ int zmq::null_mechanism_t::next_handshake_command (msg_t *msg_)
...
@@ -95,20 +102,16 @@ int zmq::null_mechanism_t::next_handshake_command (msg_t *msg_)
if
(
_zap_reply_received
&&
status_code
!=
"200"
)
{
if
(
_zap_reply_received
&&
status_code
!=
"200"
)
{
_error_command_sent
=
true
;
_error_command_sent
=
true
;
if
(
status_code
!=
"300"
)
{
if
(
status_code
!=
"300"
)
{
const
char
*
error_command_name
=
"
\5
ERROR"
;
const
size_t
error_command_name_size
=
sizeof
(
error_command_name
)
-
1
;
const
size_t
status_code_len_size
=
1
;
const
size_t
status_code_len
=
3
;
const
size_t
status_code_len
=
3
;
const
int
rc
=
msg_
->
init_size
(
const
int
rc
=
msg_
->
init_size
(
error_command_name_
size
+
status_code
_len_size
+
status_code_len
);
error_command_name_
len
+
error_reason
_len_size
+
status_code_len
);
zmq_assert
(
rc
==
0
);
zmq_assert
(
rc
==
0
);
unsigned
char
*
msg_data
=
unsigned
char
*
msg_data
=
static_cast
<
unsigned
char
*>
(
msg_
->
data
());
static_cast
<
unsigned
char
*>
(
msg_
->
data
());
memcpy
(
msg_data
,
error_command_name
,
error_command_name_
size
);
memcpy
(
msg_data
,
error_command_name
,
error_command_name_
len
);
msg_data
+=
error_command_name_
size
;
msg_data
+=
error_command_name_
len
;
*
msg_data
=
status_code_len
;
*
msg_data
=
status_code_len
;
msg_data
+=
status_code
_len_size
;
msg_data
+=
error_reason
_len_size
;
memcpy
(
msg_data
,
status_code
.
c_str
(),
status_code_len
);
memcpy
(
msg_data
,
status_code
.
c_str
(),
status_code_len
);
return
0
;
return
0
;
}
}
...
@@ -116,7 +119,8 @@ int zmq::null_mechanism_t::next_handshake_command (msg_t *msg_)
...
@@ -116,7 +119,8 @@ int zmq::null_mechanism_t::next_handshake_command (msg_t *msg_)
return
-
1
;
return
-
1
;
}
}
make_command_with_basic_properties
(
msg_
,
"
\5
READY"
,
6
);
make_command_with_basic_properties
(
msg_
,
ready_command_name
,
ready_command_name_len
);
_ready_command_sent
=
true
;
_ready_command_sent
=
true
;
...
@@ -137,9 +141,11 @@ int zmq::null_mechanism_t::process_handshake_command (msg_t *msg_)
...
@@ -137,9 +141,11 @@ int zmq::null_mechanism_t::process_handshake_command (msg_t *msg_)
const
size_t
data_size
=
msg_
->
size
();
const
size_t
data_size
=
msg_
->
size
();
int
rc
=
0
;
int
rc
=
0
;
if
(
data_size
>=
6
&&
!
memcmp
(
cmd_data
,
"
\5
READY"
,
6
))
if
(
data_size
>=
ready_command_name_len
&&
!
memcmp
(
cmd_data
,
ready_command_name
,
ready_command_name_len
))
rc
=
process_ready_command
(
cmd_data
,
data_size
);
rc
=
process_ready_command
(
cmd_data
,
data_size
);
else
if
(
data_size
>=
6
&&
!
memcmp
(
cmd_data
,
"
\5
ERROR"
,
6
))
else
if
(
data_size
>=
error_command_name_len
&&
!
memcmp
(
cmd_data
,
error_command_name
,
error_command_name_len
))
rc
=
process_error_command
(
cmd_data
,
data_size
);
rc
=
process_error_command
(
cmd_data
,
data_size
);
else
{
else
{
session
->
get_socket
()
->
event_handshake_failed_protocol
(
session
->
get_socket
()
->
event_handshake_failed_protocol
(
...
@@ -161,13 +167,16 @@ int zmq::null_mechanism_t::process_ready_command (
...
@@ -161,13 +167,16 @@ int zmq::null_mechanism_t::process_ready_command (
const
unsigned
char
*
cmd_data_
,
size_t
data_size_
)
const
unsigned
char
*
cmd_data_
,
size_t
data_size_
)
{
{
_ready_command_received
=
true
;
_ready_command_received
=
true
;
return
parse_metadata
(
cmd_data_
+
6
,
data_size_
-
6
);
return
parse_metadata
(
cmd_data_
+
ready_command_name_len
,
data_size_
-
ready_command_name_len
);
}
}
int
zmq
::
null_mechanism_t
::
process_error_command
(
int
zmq
::
null_mechanism_t
::
process_error_command
(
const
unsigned
char
*
cmd_data_
,
size_t
data_size_
)
const
unsigned
char
*
cmd_data_
,
size_t
data_size_
)
{
{
if
(
data_size_
<
7
)
{
const
size_t
fixed_prefix_size
=
error_command_name_len
+
error_reason_len_size
;
if
(
data_size_
<
fixed_prefix_size
)
{
session
->
get_socket
()
->
event_handshake_failed_protocol
(
session
->
get_socket
()
->
event_handshake_failed_protocol
(
session
->
get_endpoint
(),
session
->
get_endpoint
(),
ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_ERROR
);
ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_ERROR
);
...
@@ -175,8 +184,9 @@ int zmq::null_mechanism_t::process_error_command (
...
@@ -175,8 +184,9 @@ int zmq::null_mechanism_t::process_error_command (
errno
=
EPROTO
;
errno
=
EPROTO
;
return
-
1
;
return
-
1
;
}
}
const
size_t
error_reason_len
=
static_cast
<
size_t
>
(
cmd_data_
[
6
]);
const
size_t
error_reason_len
=
if
(
error_reason_len
>
data_size_
-
7
)
{
static_cast
<
size_t
>
(
cmd_data_
[
error_command_name_len
]);
if
(
error_reason_len
>
data_size_
-
fixed_prefix_size
)
{
session
->
get_socket
()
->
event_handshake_failed_protocol
(
session
->
get_socket
()
->
event_handshake_failed_protocol
(
session
->
get_endpoint
(),
session
->
get_endpoint
(),
ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_ERROR
);
ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_ERROR
);
...
@@ -184,7 +194,8 @@ int zmq::null_mechanism_t::process_error_command (
...
@@ -184,7 +194,8 @@ int zmq::null_mechanism_t::process_error_command (
errno
=
EPROTO
;
errno
=
EPROTO
;
return
-
1
;
return
-
1
;
}
}
const
char
*
error_reason
=
reinterpret_cast
<
const
char
*>
(
cmd_data_
)
+
7
;
const
char
*
error_reason
=
reinterpret_cast
<
const
char
*>
(
cmd_data_
)
+
fixed_prefix_size
;
handle_error_reason
(
error_reason
,
error_reason_len
);
handle_error_reason
(
error_reason
,
error_reason_len
);
_error_command_received
=
true
;
_error_command_received
=
true
;
return
0
;
return
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment