plain_server.hpp 2.3 KB
Newer Older
1
/*
2
    Copyright (c) 2007-2015 Contributors as noted in the AUTHORS file
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

    This file is part of 0MQ.

    0MQ is free software; you can redistribute it and/or modify it under
    the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    0MQ is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

20 21
#ifndef __ZMQ_PLAIN_SERVER_HPP_INCLUDED__
#define __ZMQ_PLAIN_SERVER_HPP_INCLUDED__
22 23 24 25 26 27 28 29

#include "mechanism.hpp"
#include "options.hpp"

namespace zmq
{

    class msg_t;
30
    class session_base_t;
31

32
    class plain_server_t : public mechanism_t
33 34 35
    {
    public:

36 37 38 39
        plain_server_t (session_base_t *session_,
                        const std::string &peer_address_,
                        const options_t &options_);
        virtual ~plain_server_t ();
40 41

        // mechanism implementation
42 43
        virtual int next_handshake_command (msg_t *msg_);
        virtual int process_handshake_command (msg_t *msg_);
44
        virtual int zap_msg_available ();
45
        virtual status_t status () const;
46 47 48 49 50 51 52 53

    private:

        enum state_t {
            waiting_for_hello,
            sending_welcome,
            waiting_for_initiate,
            sending_ready,
54
            waiting_for_zap_reply,
55 56
            sending_error,
            error_command_sent,
57 58 59
            ready
        };

60
        session_base_t * const session;
61

62 63
        const std::string peer_address;

64 65
        //  Status code as received from ZAP handler
        std::string status_code;
66

67 68
        state_t state;

69 70
        int produce_welcome (msg_t *msg_) const;
        int produce_ready (msg_t *msg_) const;
71
        int produce_error (msg_t *msg_) const;
72

73 74
        int process_hello (msg_t *msg_);
        int process_initiate (msg_t *msg_);
75

76 77
        void send_zap_request (const std::string &username,
                               const std::string &password);
78
        int receive_and_process_zap_reply ();
79 80 81 82 83
    };

}

#endif