1 | /* |
2 | Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file |
3 | |
4 | This file is part of libzmq, the ZeroMQ core engine in C++. |
5 | |
6 | libzmq is free software; you can redistribute it and/or modify it under |
7 | the terms of the GNU Lesser General Public License (LGPL) as published |
8 | by the Free Software Foundation; either version 3 of the License, or |
9 | (at your option) any later version. |
10 | |
11 | As a special exception, the Contributors give you permission to link |
12 | this library with independent modules to produce an executable, |
13 | regardless of the license terms of these independent modules, and to |
14 | copy and distribute the resulting executable under terms of your choice, |
15 | provided that you also meet, for each linked independent module, the |
16 | terms and conditions of the license of that module. An independent |
17 | module is a module which is not derived from or based on this library. |
18 | If you modify this library, you must extend this exception to your |
19 | version of the library. |
20 | |
21 | libzmq is distributed in the hope that it will be useful, but WITHOUT |
22 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
23 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
24 | License for more details. |
25 | |
26 | You should have received a copy of the GNU Lesser General Public License |
27 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
28 | */ |
29 | |
30 | #ifndef __ZMQ_ZAP_CLIENT_HPP_INCLUDED__ |
31 | #define __ZMQ_ZAP_CLIENT_HPP_INCLUDED__ |
32 | |
33 | #include "mechanism_base.hpp" |
34 | |
35 | namespace zmq |
36 | { |
37 | class zap_client_t : public virtual mechanism_base_t |
38 | { |
39 | public: |
40 | zap_client_t (session_base_t *const session_, |
41 | const std::string &peer_address_, |
42 | const options_t &options_); |
43 | |
44 | void send_zap_request (const char *mechanism_, |
45 | size_t mechanism_length_, |
46 | const uint8_t *credentials_, |
47 | size_t credentials_size_); |
48 | |
49 | void send_zap_request (const char *mechanism_, |
50 | size_t mechanism_length_, |
51 | const uint8_t **credentials_, |
52 | size_t *credentials_sizes_, |
53 | size_t credentials_count_); |
54 | |
55 | virtual int receive_and_process_zap_reply (); |
56 | virtual void handle_zap_status_code (); |
57 | |
58 | protected: |
59 | const std::string peer_address; |
60 | |
61 | // Status code as received from ZAP handler |
62 | std::string status_code; |
63 | }; |
64 | |
65 | class zap_client_common_handshake_t : public zap_client_t |
66 | { |
67 | protected: |
68 | enum state_t |
69 | { |
70 | waiting_for_hello, |
71 | sending_welcome, |
72 | waiting_for_initiate, |
73 | waiting_for_zap_reply, |
74 | sending_ready, |
75 | sending_error, |
76 | error_sent, |
77 | ready |
78 | }; |
79 | |
80 | zap_client_common_handshake_t (session_base_t *const session_, |
81 | const std::string &peer_address_, |
82 | const options_t &options_, |
83 | state_t zap_reply_ok_state_); |
84 | |
85 | // methods from mechanism_t |
86 | status_t status () const; |
87 | int zap_msg_available (); |
88 | |
89 | // zap_client_t methods |
90 | int receive_and_process_zap_reply (); |
91 | void handle_zap_status_code (); |
92 | |
93 | // Current FSM state |
94 | state_t state; |
95 | |
96 | private: |
97 | const state_t _zap_reply_ok_state; |
98 | }; |
99 | } |
100 | |
101 | #endif |
102 | |