libzmq  master
ZeroMQ C++ Core Engine (LIBZMQ)
socks.hpp
Go to the documentation of this file.
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_SOCKS_HPP_INCLUDED__
31 #define __ZMQ_SOCKS_HPP_INCLUDED__
32 
33 #include <string>
34 #include "fd.hpp"
35 #include "stdint.hpp"
36 
37 namespace zmq
38 {
39 
41  {
42  socks_greeting_t (uint8_t method);
43  socks_greeting_t (uint8_t *methods_, uint8_t num_methods_);
44 
45  uint8_t methods [UINT8_MAX];
46  const size_t num_methods;
47  };
48 
50  {
51  public:
53  void encode (const socks_greeting_t &greeting_);
54  int output (fd_t fd_);
55  bool has_pending_data () const;
56  void reset ();
57 
58  private:
59  size_t bytes_encoded;
60  size_t bytes_written;
61  uint8_t buf [2 + UINT8_MAX];
62  };
63 
65  {
66  socks_choice_t (uint8_t method_);
67 
68  uint8_t method;
69  };
70 
72  {
73  public:
75  int input (fd_t fd_);
76  bool message_ready () const;
77  socks_choice_t decode ();
78  void reset ();
79 
80  private:
81  unsigned char buf [2];
82  size_t bytes_read;
83  };
84 
86  {
88  uint8_t command_, std::string hostname_, uint16_t port_);
89 
90  const uint8_t command;
91  const std::string hostname;
92  const uint16_t port;
93  };
94 
96  {
97  public:
99  void encode (const socks_request_t &req);
100  int output (fd_t fd_);
101  bool has_pending_data () const;
102  void reset ();
103 
104  private:
107  uint8_t buf [4 + UINT8_MAX + 1 + 2];
108  };
109 
111  {
113  uint8_t response_code_, std::string address_, uint16_t port_);
114  uint8_t response_code;
115  std::string address;
116  uint16_t port;
117  };
118 
120  {
121  public:
123  int input (fd_t fd_);
124  bool message_ready () const;
125  socks_response_t decode ();
126  void reset ();
127 
128  private:
129  int8_t buf [4 + UINT8_MAX + 1 + 2];
130  size_t bytes_read;
131  };
132 
133 }
134 
135 #endif
const uint8_t command
Definition: socks.hpp:90
const size_t num_methods
Definition: socks.hpp:46
std::string address
Definition: socks.hpp:115
uint8_t method
Definition: socks.hpp:68
const uint16_t port
Definition: socks.hpp:92
uint8_t response_code
Definition: socks.hpp:114
#define UINT8_MAX
Definition: stdint.hpp:73
Definition: address.hpp:35
uint8_t methods[UINT8_MAX]
Definition: socks.hpp:45
socks_greeting_t(uint8_t method)
Definition: socks.cpp:44
const std::string hostname
Definition: socks.hpp:91