~ubuntu-branches/ubuntu/wily/zeromq3/wily-proposed

« back to all changes in this revision

Viewing changes to .pc/protocol-downgrade-attack.patch/src/session_base.hpp

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2015-05-05 21:06:02 UTC
  • Revision ID: package-import@ubuntu.com-20150505210602-7nmw5z31bei3puj6
Tags: 4.0.5+dfsg-3
V3 protocol handler vulnerable to downgrade attacks, use upstream
backported fix for this issue (closes: #784366).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
 
3
 
 
4
    This file is part of 0MQ.
 
5
 
 
6
    0MQ is free software; you can redistribute it and/or modify it under
 
7
    the terms of the GNU Lesser General Public License as published by
 
8
    the Free Software Foundation; either version 3 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    0MQ is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
    GNU Lesser General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU Lesser General Public License
 
17
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
#ifndef __ZMQ_SESSION_BASE_HPP_INCLUDED__
 
21
#define __ZMQ_SESSION_BASE_HPP_INCLUDED__
 
22
 
 
23
#include <string>
 
24
#include <stdarg.h>
 
25
 
 
26
#include "own.hpp"
 
27
#include "io_object.hpp"
 
28
#include "pipe.hpp"
 
29
#include "socket_base.hpp"
 
30
 
 
31
namespace zmq
 
32
{
 
33
 
 
34
    class pipe_t;
 
35
    class io_thread_t;
 
36
    class socket_base_t;
 
37
    struct i_engine;
 
38
    struct address_t;
 
39
 
 
40
    class session_base_t :
 
41
        public own_t,
 
42
        public io_object_t,
 
43
        public i_pipe_events
 
44
    {
 
45
    public:
 
46
 
 
47
        //  Create a session of the particular type.
 
48
        static session_base_t *create (zmq::io_thread_t *io_thread_,
 
49
            bool connect_, zmq::socket_base_t *socket_,
 
50
            const options_t &options_, const address_t *addr_);
 
51
 
 
52
        //  To be used once only, when creating the session.
 
53
        void attach_pipe (zmq::pipe_t *pipe_);
 
54
 
 
55
        //  Following functions are the interface exposed towards the engine.
 
56
        virtual void reset ();
 
57
        void flush ();
 
58
        void detach ();
 
59
 
 
60
        //  i_pipe_events interface implementation.
 
61
        void read_activated (zmq::pipe_t *pipe_);
 
62
        void write_activated (zmq::pipe_t *pipe_);
 
63
        void hiccuped (zmq::pipe_t *pipe_);
 
64
        void pipe_terminated (zmq::pipe_t *pipe_);
 
65
 
 
66
        //  Delivers a message. Returns 0 if successful; -1 otherwise.
 
67
        //  The function takes ownership of the message.
 
68
        int push_msg (msg_t *msg_);
 
69
 
 
70
        int zap_connect ();
 
71
 
 
72
        //  Fetches a message. Returns 0 if successful; -1 otherwise.
 
73
        //  The caller is responsible for freeing the message when no
 
74
        //  longer used.
 
75
        int pull_msg (msg_t *msg_);
 
76
 
 
77
        //  Receives message from ZAP socket.
 
78
        //  Returns 0 on success; -1 otherwise.
 
79
        //  The caller is responsible for freeing the message.
 
80
        int read_zap_msg (msg_t *msg_);
 
81
 
 
82
        //  Sends message to ZAP socket.
 
83
        //  Returns 0 on success; -1 otherwise.
 
84
        //  The function takes ownership of the message.
 
85
        int write_zap_msg (msg_t *msg_);
 
86
 
 
87
        socket_base_t *get_socket ();
 
88
 
 
89
    protected:
 
90
 
 
91
        session_base_t (zmq::io_thread_t *io_thread_, bool connect_,
 
92
            zmq::socket_base_t *socket_, const options_t &options_,
 
93
            const address_t *addr_);
 
94
        virtual ~session_base_t ();
 
95
 
 
96
    private:
 
97
 
 
98
        void start_connecting (bool wait_);
 
99
 
 
100
        void detached ();
 
101
 
 
102
        //  Handlers for incoming commands.
 
103
        void process_plug ();
 
104
        void process_attach (zmq::i_engine *engine_);
 
105
        void process_term (int linger_);
 
106
 
 
107
        //  i_poll_events handlers.
 
108
        void timer_event (int id_);
 
109
 
 
110
        //  Remove any half processed messages. Flush unflushed messages.
 
111
        //  Call this function when engine disconnect to get rid of leftovers.
 
112
        void clean_pipes ();
 
113
 
 
114
        //  Call this function to move on with the delayed process_term.
 
115
        void proceed_with_term ();
 
116
 
 
117
        //  If true, this session (re)connects to the peer. Otherwise, it's
 
118
        //  a transient session created by the listener.
 
119
        bool connect;
 
120
 
 
121
        //  Pipe connecting the session to its socket.
 
122
        zmq::pipe_t *pipe;
 
123
 
 
124
        //  Pipe used to exchange messages with ZAP socket.
 
125
        zmq::pipe_t *zap_pipe;
 
126
 
 
127
        //  This set is added to with pipes we are disconnecting, but haven't yet completed
 
128
        std::set <pipe_t *> terminating_pipes;
 
129
 
 
130
        //  This flag is true if the remainder of the message being processed
 
131
        //  is still in the in pipe.
 
132
        bool incomplete_in;
 
133
 
 
134
        //  True if termination have been suspended to push the pending
 
135
        //  messages to the network.
 
136
        bool pending;
 
137
 
 
138
        //  The protocol I/O engine connected to the session.
 
139
        zmq::i_engine *engine;
 
140
 
 
141
        //  The socket the session belongs to.
 
142
        zmq::socket_base_t *socket;
 
143
 
 
144
        //  I/O thread the session is living in. It will be used to plug in
 
145
        //  the engines into the same thread.
 
146
        zmq::io_thread_t *io_thread;
 
147
 
 
148
        //  ID of the linger timer
 
149
        enum {linger_timer_id = 0x20};
 
150
 
 
151
        //  True is linger timer is running.
 
152
        bool has_linger_timer;
 
153
 
 
154
        //  Protocol and address to use when connecting.
 
155
        const address_t *addr;
 
156
 
 
157
        session_base_t (const session_base_t&);
 
158
        const session_base_t &operator = (const session_base_t&);
 
159
    };
 
160
 
 
161
}
 
162
 
 
163
#endif