LCOV - code coverage report
Current view: top level - home/h/core/forks/m4-libzmq/src - mechanism.hpp (source / functions) Hit Total Coverage
Test: zeromq-4.2.0 Code Coverage Lines: 2 3 66.7 %
Date: 2016-05-09 Functions: 2 3 66.7 %
Legend: Lines: hit not hit

          Line data    Source code
       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_MECHANISM_HPP_INCLUDED__
      31             : #define __ZMQ_MECHANISM_HPP_INCLUDED__
      32             : 
      33             : #include "stdint.hpp"
      34             : #include "options.hpp"
      35             : #include "blob.hpp"
      36             : #include "metadata.hpp"
      37             : 
      38             : namespace zmq
      39             : {
      40             : 
      41             :     //  Abstract class representing security mechanism.
      42             :     //  Different mechanism extends this class.
      43             : 
      44             :     class msg_t;
      45             : 
      46             :     class mechanism_t
      47             :     {
      48             :     public:
      49             : 
      50             :         enum status_t {
      51             :             handshaking,
      52             :             ready,
      53             :             error
      54             :         };
      55             : 
      56             :         mechanism_t (const options_t &options_);
      57             : 
      58             :         virtual ~mechanism_t ();
      59             : 
      60             :         //  Prepare next handshake command that is to be sent to the peer.
      61             :         virtual int next_handshake_command (msg_t *msg_) = 0;
      62             : 
      63             :         //  Process the handshake command received from the peer.
      64             :         virtual int process_handshake_command (msg_t *msg_) = 0;
      65             : 
      66      635082 :         virtual int encode (msg_t *) { return 0; }
      67             : 
      68      635073 :         virtual int decode (msg_t *) { return 0; }
      69             : 
      70             :         //  Notifies mechanism about availability of ZAP message.
      71           0 :         virtual int zap_msg_available () { return 0; }
      72             : 
      73             :         //  Returns the status of this mechanism.
      74             :         virtual status_t status () const = 0;
      75             : 
      76             :         void set_peer_identity (const void *id_ptr, size_t id_size);
      77             : 
      78             :         void peer_identity (msg_t *msg_);
      79             : 
      80             :         void set_user_id (const void *user_id, size_t size);
      81             : 
      82             :         blob_t get_user_id () const;
      83             : 
      84             :         const metadata_t::dict_t& get_zmtp_properties () {
      85             :             return zmtp_properties;
      86             :         }
      87             : 
      88             :         const metadata_t::dict_t& get_zap_properties () {
      89             :             return zap_properties;
      90             :         }
      91             : 
      92             :     protected:
      93             : 
      94             :         //  Only used to identify the socket for the Socket-Type
      95             :         //  property in the wire protocol.
      96             :         const char *socket_type_string (int socket_type) const;
      97             : 
      98             :         size_t add_property (unsigned char *ptr, const char *name,
      99             :             const void *value, size_t value_len) const;
     100             : 
     101             :         //  Parses a metadata.
     102             :         //  Metadata consists of a list of properties consisting of
     103             :         //  name and value as size-specified strings.
     104             :         //  Returns 0 on success and -1 on error, in which case errno is set.
     105             :         int parse_metadata (
     106             :             const unsigned char *ptr_, size_t length, bool zap_flag = false);
     107             : 
     108             :         //  This is called by parse_property method whenever it
     109             :         //  parses a new property. The function should return 0
     110             :         //  on success and -1 on error, in which case it should
     111             :         //  set errno. Signaling error prevents parser from
     112             :         //  parsing remaining data.
     113             :         //  Derived classes are supposed to override this
     114             :         //  method to handle custom processing.
     115             :         virtual int property (const std::string& name_,
     116             :                               const void *value_, size_t length_);
     117             : 
     118             :         //  Properties received from ZMTP peer.
     119             :         metadata_t::dict_t zmtp_properties;
     120             : 
     121             :         //  Properties received from ZAP server.
     122             :         metadata_t::dict_t zap_properties;
     123             : 
     124             :         options_t options;
     125             : 
     126             :     private:
     127             : 
     128             :         blob_t identity;
     129             : 
     130             :         blob_t user_id;
     131             : 
     132             :         //  Returns true iff socket associated with the mechanism
     133             :         //  is compatible with a given socket type 'type_'.
     134             :         bool check_socket_type (const std::string& type_) const;
     135             :     };
     136             : 
     137             : }
     138             : 
     139             : #endif

Generated by: LCOV version 1.10