2013-05-13 22:34:27 +02:00
|
|
|
/*
|
2014-01-02 12:00:57 +01:00
|
|
|
Copyright (c) 2007-2014 Contributors as noted in the AUTHORS file
|
2013-05-13 22:34:27 +02:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
{
|
|
|
|
|
|
|
|
// Abstract class representing security mechanism.
|
|
|
|
// Different mechanism extedns this class.
|
|
|
|
|
|
|
|
class msg_t;
|
|
|
|
|
|
|
|
class mechanism_t
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-05-06 17:07:50 +02:00
|
|
|
enum status_t {
|
|
|
|
handshaking,
|
|
|
|
ready,
|
|
|
|
error
|
|
|
|
};
|
|
|
|
|
2013-05-13 22:34:27 +02:00
|
|
|
mechanism_t (const options_t &options_);
|
|
|
|
|
|
|
|
virtual ~mechanism_t ();
|
|
|
|
|
2013-09-04 17:59:45 +02:00
|
|
|
// Prepare next handshake command that is to be sent to the peer.
|
|
|
|
virtual int next_handshake_command (msg_t *msg_) = 0;
|
2013-05-13 22:34:27 +02:00
|
|
|
|
2013-09-04 17:59:45 +02:00
|
|
|
// Process the handshake command received from the peer.
|
|
|
|
virtual int process_handshake_command (msg_t *msg_) = 0;
|
2013-05-13 22:34:27 +02:00
|
|
|
|
2014-01-18 13:08:06 -08:00
|
|
|
virtual int encode (msg_t *) { return 0; }
|
2013-06-22 11:46:40 +02:00
|
|
|
|
2014-01-18 13:08:06 -08:00
|
|
|
virtual int decode (msg_t *) { return 0; }
|
2013-06-22 11:46:40 +02:00
|
|
|
|
2013-06-06 13:13:10 +02:00
|
|
|
// Notifies mechanism about availability of ZAP message.
|
|
|
|
virtual int zap_msg_available () { return 0; }
|
|
|
|
|
2014-05-06 17:07:50 +02:00
|
|
|
// Returns the status of this mechanism.
|
|
|
|
virtual status_t status () const = 0;
|
2013-05-13 22:34:27 +02:00
|
|
|
|
|
|
|
void set_peer_identity (const void *id_ptr, size_t id_size);
|
|
|
|
|
|
|
|
void peer_identity (msg_t *msg_);
|
|
|
|
|
2014-01-12 21:58:36 +01:00
|
|
|
void set_user_id (const void *user_id, size_t size);
|
|
|
|
|
|
|
|
blob_t get_user_id () const;
|
|
|
|
|
2014-05-02 12:33:26 +02:00
|
|
|
const metadata_t::dict_t& get_zmtp_properties () {
|
|
|
|
return zmtp_properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
const metadata_t::dict_t& get_zap_properties () {
|
|
|
|
return zap_properties;
|
|
|
|
}
|
2014-04-30 14:17:38 +02:00
|
|
|
|
2013-05-13 22:34:27 +02:00
|
|
|
protected:
|
|
|
|
|
2013-06-21 16:56:45 +01:00
|
|
|
// Only used to identify the socket for the Socket-Type
|
|
|
|
// property in the wire protocol.
|
2013-05-13 22:34:27 +02:00
|
|
|
const char *socket_type_string (int socket_type) const;
|
|
|
|
|
|
|
|
size_t add_property (unsigned char *ptr, const char *name,
|
|
|
|
const void *value, size_t value_len) const;
|
|
|
|
|
2013-06-23 08:52:27 +02:00
|
|
|
// Parses a metadata.
|
|
|
|
// Metadata consists of a list of properties consisting of
|
|
|
|
// name and value as size-specified strings.
|
|
|
|
// Returns 0 on success and -1 on error, in which case errno is set.
|
2014-04-30 14:17:38 +02:00
|
|
|
int parse_metadata (
|
|
|
|
const unsigned char *ptr_, size_t length, bool zap_flag = false);
|
2013-06-22 19:02:08 +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
|
2013-06-23 08:52:27 +02:00
|
|
|
// set errno. Signaling error prevents parser from
|
2013-06-22 19:02:08 +02:00
|
|
|
// parsing remaining data.
|
|
|
|
// Derived classes are supposed to override this
|
|
|
|
// method to handle custom processing.
|
2014-01-29 15:58:53 +04:00
|
|
|
virtual int property (const std::string& name_,
|
2013-06-22 19:02:08 +02:00
|
|
|
const void *value_, size_t length_);
|
|
|
|
|
2014-05-02 12:33:26 +02:00
|
|
|
// Properties received from ZMTP peer.
|
|
|
|
metadata_t::dict_t zmtp_properties;
|
|
|
|
|
|
|
|
// Properties received from ZAP server.
|
|
|
|
metadata_t::dict_t zap_properties;
|
2014-04-30 14:17:38 +02:00
|
|
|
|
2013-05-13 22:34:27 +02:00
|
|
|
options_t options;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
blob_t identity;
|
2013-07-01 10:04:54 +02:00
|
|
|
|
2014-01-12 21:58:36 +01:00
|
|
|
blob_t user_id;
|
|
|
|
|
2013-07-01 10:04:54 +02:00
|
|
|
// Returns true iff socket associated with the mechanism
|
|
|
|
// is compatible with a given socket type 'type_'.
|
2014-01-29 15:58:53 +04:00
|
|
|
bool check_socket_type (const std::string& type_) const;
|
2013-05-13 22:34:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|