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
13df8e65
Commit
13df8e65
authored
Jun 22, 2013
by
Ian Barber
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
git://github.com/zeromq/libzmq
parents
211bf2b0
73e19527
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
82 deletions
+87
-82
pipe.cpp
src/pipe.cpp
+8
-12
pipe.hpp
src/pipe.hpp
+1
-1
plain_mechanism.cpp
src/plain_mechanism.cpp
+72
-69
plain_mechanism.hpp
src/plain_mechanism.hpp
+6
-0
No files found.
src/pipe.cpp
View file @
13df8e65
...
@@ -113,7 +113,7 @@ bool zmq::pipe_t::check_read ()
...
@@ -113,7 +113,7 @@ bool zmq::pipe_t::check_read ()
msg_t
msg
;
msg_t
msg
;
bool
ok
=
inpipe
->
read
(
&
msg
);
bool
ok
=
inpipe
->
read
(
&
msg
);
zmq_assert
(
ok
);
zmq_assert
(
ok
);
delimit
();
process_delimiter
();
return
false
;
return
false
;
}
}
...
@@ -134,7 +134,7 @@ bool zmq::pipe_t::read (msg_t *msg_)
...
@@ -134,7 +134,7 @@ bool zmq::pipe_t::read (msg_t *msg_)
// If delimiter was read, start termination process of the pipe.
// If delimiter was read, start termination process of the pipe.
if
(
msg_
->
is_delimiter
())
{
if
(
msg_
->
is_delimiter
())
{
delimit
();
process_delimiter
();
return
false
;
return
false
;
}
}
...
@@ -414,22 +414,18 @@ int zmq::pipe_t::compute_lwm (int hwm_)
...
@@ -414,22 +414,18 @@ int zmq::pipe_t::compute_lwm (int hwm_)
return
result
;
return
result
;
}
}
void
zmq
::
pipe_t
::
delimit
()
void
zmq
::
pipe_t
::
process_delimiter
()
{
{
if
(
state
==
active
)
{
zmq_assert
(
state
==
active
state
=
delimiter_received
;
||
state
==
waiting_for_delimiter
);
return
;
}
if
(
state
==
waiting_for_delimiter
)
{
if
(
state
==
active
)
state
=
delimiter_received
;
else
{
outpipe
=
NULL
;
outpipe
=
NULL
;
send_pipe_term_ack
(
peer
);
send_pipe_term_ack
(
peer
);
state
=
term_ack_sent
;
state
=
term_ack_sent
;
return
;
}
}
// Delimiter in any other state is invalid.
zmq_assert
(
false
);
}
}
void
zmq
::
pipe_t
::
hiccup
()
void
zmq
::
pipe_t
::
hiccup
()
...
...
src/pipe.hpp
View file @
13df8e65
...
@@ -120,7 +120,7 @@ namespace zmq
...
@@ -120,7 +120,7 @@ namespace zmq
void
process_pipe_term_ack
();
void
process_pipe_term_ack
();
// Handler for delimiter read from the pipe.
// Handler for delimiter read from the pipe.
void
delimit
();
void
process_delimiter
();
// Constructor is private. Pipe can only be created using
// Constructor is private. Pipe can only be created using
// pipepair function.
// pipepair function.
...
...
src/plain_mechanism.cpp
View file @
13df8e65
...
@@ -35,6 +35,7 @@ zmq::plain_mechanism_t::plain_mechanism_t (session_base_t *session_,
...
@@ -35,6 +35,7 @@ zmq::plain_mechanism_t::plain_mechanism_t (session_base_t *session_,
const
options_t
&
options_
)
:
const
options_t
&
options_
)
:
mechanism_t
(
options_
),
mechanism_t
(
options_
),
session
(
session_
),
session
(
session_
),
expecting_zap_reply
(
false
),
state
(
options
.
as_server
?
waiting_for_hello
:
sending_hello
)
state
(
options
.
as_server
?
waiting_for_hello
:
sending_hello
)
{
{
}
}
...
@@ -82,16 +83,8 @@ int zmq::plain_mechanism_t::process_handshake_message (msg_t *msg_)
...
@@ -82,16 +83,8 @@ int zmq::plain_mechanism_t::process_handshake_message (msg_t *msg_)
switch
(
state
)
{
switch
(
state
)
{
case
waiting_for_hello
:
case
waiting_for_hello
:
rc
=
process_hello_command
(
msg_
);
rc
=
process_hello_command
(
msg_
);
if
(
rc
==
0
)
{
if
(
rc
==
0
)
rc
=
receive_and_process_zap_reply
();
state
=
expecting_zap_reply
?
waiting_for_zap_reply
:
sending_welcome
;
if
(
rc
==
0
)
state
=
sending_welcome
;
else
if
(
errno
==
EAGAIN
)
{
rc
=
0
;
state
=
waiting_for_zap_reply
;
}
}
break
;
break
;
case
waiting_for_welcome
:
case
waiting_for_welcome
:
rc
=
process_welcome_command
(
msg_
);
rc
=
process_welcome_command
(
msg_
);
...
@@ -216,68 +209,18 @@ int zmq::plain_mechanism_t::process_hello_command (msg_t *msg_)
...
@@ -216,68 +209,18 @@ int zmq::plain_mechanism_t::process_hello_command (msg_t *msg_)
return
-
1
;
return
-
1
;
}
}
// Use ZAP protocol (RFC 27) to authenticate user.
// Use ZAP protocol (RFC 27) to authenticate
the
user.
int
rc
=
session
->
zap_connect
();
int
rc
=
session
->
zap_connect
();
if
(
rc
==
-
1
)
{
if
(
rc
==
0
)
{
errno
=
EPROTO
;
send_zap_request
(
username
,
password
);
return
-
1
;
rc
=
receive_and_process_zap_reply
();
if
(
rc
!=
0
)
{
if
(
errno
!=
EAGAIN
)
return
-
1
;
expecting_zap_reply
=
true
;
}
}
}
msg_t
msg
;
// Address delimiter frame
rc
=
msg
.
init
();
errno_assert
(
rc
==
0
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Version frame
rc
=
msg
.
init_size
(
3
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
"1.0"
,
3
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Sequence frame
rc
=
msg
.
init_size
(
1
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
"1"
,
1
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Domain frame
rc
=
msg
.
init
();
errno_assert
(
rc
==
0
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Mechanism frame
rc
=
msg
.
init_size
(
5
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
"PLAIN"
,
5
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Username frame
rc
=
msg
.
init_size
(
username_length
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
username
.
c_str
(),
username_length
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// 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
);
errno_assert
(
rc
==
0
);
return
0
;
return
0
;
}
}
...
@@ -389,6 +332,66 @@ int zmq::plain_mechanism_t::process_ready_command (msg_t *msg_)
...
@@ -389,6 +332,66 @@ int zmq::plain_mechanism_t::process_ready_command (msg_t *msg_)
return
parse_property_list
(
ptr
+
8
,
bytes_left
-
8
);
return
parse_property_list
(
ptr
+
8
,
bytes_left
-
8
);
}
}
void
zmq
::
plain_mechanism_t
::
send_zap_request
(
const
std
::
string
&
username
,
const
std
::
string
&
password
)
{
int
rc
;
msg_t
msg
;
// Address delimiter frame
rc
=
msg
.
init
();
errno_assert
(
rc
==
0
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Version frame
rc
=
msg
.
init_size
(
3
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
"1.0"
,
3
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Sequence frame
rc
=
msg
.
init_size
(
1
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
"1"
,
1
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Domain frame
rc
=
msg
.
init
();
errno_assert
(
rc
==
0
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Mechanism frame
rc
=
msg
.
init_size
(
5
);
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
"PLAIN"
,
5
);
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// Username frame
rc
=
msg
.
init_size
(
username
.
length
());
errno_assert
(
rc
==
0
);
memcpy
(
msg
.
data
(),
username
.
c_str
(),
username
.
length
());
msg
.
set_flags
(
msg_t
::
more
);
rc
=
session
->
write_zap_msg
(
&
msg
);
errno_assert
(
rc
==
0
);
// 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
);
errno_assert
(
rc
==
0
);
}
int
zmq
::
plain_mechanism_t
::
receive_and_process_zap_reply
()
int
zmq
::
plain_mechanism_t
::
receive_and_process_zap_reply
()
{
{
int
rc
=
0
;
int
rc
=
0
;
...
...
src/plain_mechanism.hpp
View file @
13df8e65
...
@@ -59,6 +59,10 @@ namespace zmq
...
@@ -59,6 +59,10 @@ namespace zmq
};
};
session_base_t
*
const
session
;
session_base_t
*
const
session
;
// True iff we are awaiting reply from ZAP reply.
bool
expecting_zap_reply
;
state_t
state
;
state_t
state
;
int
hello_command
(
msg_t
*
msg_
)
const
;
int
hello_command
(
msg_t
*
msg_
)
const
;
...
@@ -71,6 +75,8 @@ namespace zmq
...
@@ -71,6 +75,8 @@ namespace zmq
int
process_ready_command
(
msg_t
*
msg_
);
int
process_ready_command
(
msg_t
*
msg_
);
int
process_initiate_command
(
msg_t
*
msg_
);
int
process_initiate_command
(
msg_t
*
msg_
);
void
send_zap_request
(
const
std
::
string
&
username
,
const
std
::
string
&
password
);
int
receive_and_process_zap_reply
();
int
receive_and_process_zap_reply
();
int
parse_property_list
(
const
unsigned
char
*
ptr
,
size_t
length
);
int
parse_property_list
(
const
unsigned
char
*
ptr
,
size_t
length
);
...
...
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