2013-05-13 22:34:27 +02:00
|
|
|
/*
|
2016-01-28 15:07:31 +01:00
|
|
|
Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
|
2013-05-13 22:34:27 +02:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
This file is part of libzmq, the ZeroMQ core engine in C++.
|
2013-05-13 22:34:27 +02:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
libzmq is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
|
|
|
by the Free Software Foundation; either version 3 of the License, or
|
2013-05-13 22:34:27 +02:00
|
|
|
(at your option) any later version.
|
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
As a special exception, the Contributors give you permission to link
|
|
|
|
this library with independent modules to produce an executable,
|
|
|
|
regardless of the license terms of these independent modules, and to
|
|
|
|
copy and distribute the resulting executable under terms of your choice,
|
|
|
|
provided that you also meet, for each linked independent module, the
|
|
|
|
terms and conditions of the license of that module. An independent
|
|
|
|
module is a module which is not derived from or based on this library.
|
|
|
|
If you modify this library, you must extend this exception to your
|
|
|
|
version of the library.
|
|
|
|
|
|
|
|
libzmq 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.
|
2013-05-13 22:34:27 +02:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __ZMQ_MECHANISM_HPP_INCLUDED__
|
|
|
|
#define __ZMQ_MECHANISM_HPP_INCLUDED__
|
|
|
|
|
2013-05-19 10:01:33 +01:00
|
|
|
#include "stdint.hpp"
|
2013-05-13 22:34:27 +02:00
|
|
|
#include "options.hpp"
|
|
|
|
#include "blob.hpp"
|
2014-04-30 14:17:38 +02:00
|
|
|
#include "metadata.hpp"
|
2013-05-13 22:34:27 +02:00
|
|
|
|
|
|
|
namespace zmq
|
|
|
|
{
|
2017-08-18 10:04:58 +02:00
|
|
|
class msg_t;
|
|
|
|
class session_base_t;
|
2013-05-13 22:34:27 +02:00
|
|
|
|
2017-08-18 10:04:58 +02:00
|
|
|
// Abstract class representing security mechanism.
|
|
|
|
// Different mechanism extends this class.
|
|
|
|
|
2013-05-13 22:34:27 +02:00
|
|
|
class mechanism_t
|
2018-02-01 11:46:09 +01:00
|
|
|
{
|
|
|
|
public:
|
2014-05-06 17:07:50 +02:00
|
|
|
enum status_t
|
2013-05-13 22:34:27 +02:00
|
|
|
{
|
2014-05-06 17:07:50 +02:00
|
|
|
handshaking,
|
|
|
|
ready,
|
|
|
|
error
|
|
|
|
};
|
2013-05-13 22:34:27 +02:00
|
|
|
|
2013-09-04 17:59:45 +02:00
|
|
|
mechanism_t (const options_t &options_);
|
2013-05-13 22:34:27 +02:00
|
|
|
|
2014-01-18 13:08:06 -08:00
|
|
|
virtual ~mechanism_t ();
|
2013-06-22 11:46:40 +02:00
|
|
|
|
2014-01-18 13:08:06 -08:00
|
|
|
// Prepare next handshake command that is to be sent to the peer.
|
|
|
|
virtual int next_handshake_command (msg_t *msg_) = 0;
|
2013-06-22 11:46:40 +02:00
|
|
|
|
2013-06-06 13:13:10 +02:00
|
|
|
// Process the handshake command received from the peer.
|
|
|
|
virtual int process_handshake_command (msg_t *msg_) = 0;
|
|
|
|
|
2014-05-06 17:07:50 +02:00
|
|
|
virtual int encode (msg_t *) { return 0; }
|
2013-05-13 22:34:27 +02:00
|
|
|
|
2017-09-06 17:45:56 +02:00
|
|
|
virtual int decode (msg_t *) { return 0; }
|
2013-05-13 22:34:27 +02:00
|
|
|
|
2017-09-06 17:45:56 +02:00
|
|
|
// Notifies mechanism about availability of ZAP message.
|
|
|
|
virtual int zap_msg_available () { return 0; }
|
2013-05-13 22:34:27 +02:00
|
|
|
|
2014-01-12 21:58:36 +01:00
|
|
|
// Returns the status of this mechanism.
|
|
|
|
virtual status_t status () const = 0;
|
|
|
|
|
2018-05-24 17:58:30 +02:00
|
|
|
void set_peer_routing_id (const void *id_ptr_, size_t id_size_);
|
2014-01-12 21:58:36 +01:00
|
|
|
|
2014-05-02 12:33:26 +02:00
|
|
|
void peer_routing_id (msg_t *msg_);
|
|
|
|
|
2018-05-24 17:58:30 +02:00
|
|
|
void set_user_id (const void *user_id_, size_t size_);
|
2014-04-30 14:17:38 +02:00
|
|
|
|
2017-10-21 13:19:51 +02:00
|
|
|
const blob_t &get_user_id () const;
|
2013-05-13 22:34:27 +02:00
|
|
|
|
2019-12-25 15:51:26 +01:00
|
|
|
const metadata_t::dict_t &get_zmtp_properties () const
|
2018-05-29 11:08:22 +02:00
|
|
|
{
|
|
|
|
return _zmtp_properties;
|
|
|
|
}
|
2013-05-13 22:34:27 +02:00
|
|
|
|
2019-12-25 15:51:26 +01:00
|
|
|
const metadata_t::dict_t &get_zap_properties () const
|
|
|
|
{
|
|
|
|
return _zap_properties;
|
|
|
|
}
|
2017-08-15 19:42:31 +02:00
|
|
|
|
2013-05-13 22:34:27 +02:00
|
|
|
protected:
|
2017-08-15 19:42:31 +02:00
|
|
|
// Only used to identify the socket for the Socket-Type
|
|
|
|
// property in the wire protocol.
|
2019-12-25 15:51:26 +01:00
|
|
|
static const char *socket_type_string (int socket_type_);
|
2017-08-15 19:42:31 +02:00
|
|
|
|
2018-05-24 17:58:30 +02:00
|
|
|
static size_t add_property (unsigned char *ptr_,
|
|
|
|
size_t ptr_capacity_,
|
|
|
|
const char *name_,
|
|
|
|
const void *value_,
|
|
|
|
size_t value_len_);
|
|
|
|
static size_t property_len (const char *name_, size_t value_len_);
|
2013-05-13 22:34:27 +02:00
|
|
|
|
2018-05-24 17:58:30 +02:00
|
|
|
size_t add_basic_properties (unsigned char *ptr_,
|
|
|
|
size_t ptr_capacity_) const;
|
2014-04-30 14:17:38 +02:00
|
|
|
size_t basic_properties_len () const;
|
2013-06-22 19:02:08 +02:00
|
|
|
|
|
|
|
void make_command_with_basic_properties (msg_t *msg_,
|
2018-05-24 17:58:30 +02:00
|
|
|
const char *prefix_,
|
|
|
|
size_t prefix_len_) const;
|
2013-06-22 19:02:08 +02:00
|
|
|
|
2014-05-02 12:33:26 +02:00
|
|
|
// Parses a metadata.
|
|
|
|
// Metadata consists of a list of properties consisting of
|
2013-06-23 08:52:27 +02:00
|
|
|
// name and value as size-specified strings.
|
2014-05-02 12:33:26 +02:00
|
|
|
// Returns 0 on success and -1 on error, in which case errno is set.
|
2017-08-15 16:28:24 +02:00
|
|
|
int parse_metadata (const unsigned char *ptr_,
|
2018-05-24 17:58:30 +02:00
|
|
|
size_t length_,
|
|
|
|
bool zap_flag_ = false);
|
2014-05-02 12:33:26 +02:00
|
|
|
|
|
|
|
// This is called by parse_property method whenever it
|
|
|
|
// parses a new property. The function should return 0
|
|
|
|
// on success and -1 on error, in which case it should
|
|
|
|
// set errno. Signaling error prevents parser from
|
|
|
|
// parsing remaining data.
|
2013-06-22 19:02:08 +02:00
|
|
|
// Derived classes are supposed to override this
|
2014-05-02 12:33:26 +02:00
|
|
|
// method to handle custom processing.
|
2014-01-29 15:58:53 +04:00
|
|
|
virtual int
|
2014-05-02 12:33:26 +02:00
|
|
|
property (const std::string &name_, const void *value_, size_t length_);
|
2014-04-30 14:17:38 +02:00
|
|
|
|
2018-05-29 11:08:22 +02:00
|
|
|
const options_t options;
|
|
|
|
|
|
|
|
private:
|
2013-05-13 22:34:27 +02:00
|
|
|
// Properties received from ZMTP peer.
|
2018-05-29 11:08:22 +02:00
|
|
|
metadata_t::dict_t _zmtp_properties;
|
2013-05-13 22:34:27 +02:00
|
|
|
|
|
|
|
// Properties received from ZAP server.
|
2018-05-29 11:08:22 +02:00
|
|
|
metadata_t::dict_t _zap_properties;
|
2013-05-13 22:34:27 +02:00
|
|
|
|
2018-05-27 11:10:39 +02:00
|
|
|
blob_t _routing_id;
|
2014-01-12 21:58:36 +01:00
|
|
|
|
2018-05-27 11:10:39 +02:00
|
|
|
blob_t _user_id;
|
2013-05-13 22:34:27 +02:00
|
|
|
|
2013-07-01 10:04:54 +02:00
|
|
|
// Returns true iff socket associated with the mechanism
|
|
|
|
// is compatible with a given socket type 'type_'.
|
2018-02-03 16:12:49 +01:00
|
|
|
bool check_socket_type (const char *type_, size_t len_) const;
|
2018-02-01 11:46:09 +01:00
|
|
|
};
|
2017-08-18 11:34:22 +02:00
|
|
|
}
|
2013-05-13 22:34:27 +02:00
|
|
|
|
|
|
|
#endif
|