| 1 |
#ifndef PROTON_CONNECTION_OPTIONS_H |
| 2 |
#define PROTON_CONNECTION_OPTIONS_H |
| 3 |
|
| 4 |
/* |
| 5 |
* |
| 6 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 7 |
* or more contributor license agreements. See the NOTICE file |
| 8 |
* distributed with this work for additional information |
| 9 |
* regarding copyright ownership. The ASF licenses this file |
| 10 |
* to you under the Apache License, Version 2.0 (the |
| 11 |
* "License"); you may not use this file except in compliance |
| 12 |
* with the License. You may obtain a copy of the License at |
| 13 |
* |
| 14 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 15 |
* |
| 16 |
* Unless required by applicable law or agreed to in writing, |
| 17 |
* software distributed under the License is distributed on an |
| 18 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 19 |
* KIND, either express or implied. See the License for the |
| 20 |
* specific language governing permissions and limitations |
| 21 |
* under the License. |
| 22 |
* |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "./duration.hpp" |
| 26 |
#include "./fwd.hpp" |
| 27 |
#include "./internal/export.hpp" |
| 28 |
#include "./symbol.hpp" |
| 29 |
#include "./types_fwd.hpp" |
| 30 |
|
| 31 |
#include <proton/type_compat.h> |
| 32 |
|
| 33 |
#include <map> |
| 34 |
#include <memory> |
| 35 |
#include <vector> |
| 36 |
#include <string> |
| 37 |
|
| 38 |
/// @file |
| 39 |
/// @copybrief proton::connection_options |
| 40 |
|
| 41 |
struct pn_connection_t; |
| 42 |
struct pn_transport_t; |
| 43 |
|
| 44 |
namespace proton { |
| 45 |
|
| 46 |
/// Options for creating a connection. |
| 47 |
/// |
| 48 |
/// Options can be "chained" like this: |
| 49 |
/// |
| 50 |
/// @code |
| 51 |
/// c = container.connect(url, connection_options().handler(h).max_frame_size(1234)); |
| 52 |
/// @endcode |
| 53 |
/// |
| 54 |
/// You can also create an options object with common settings and use |
| 55 |
/// it as a base for different connections that have mostly the same |
| 56 |
/// settings: |
| 57 |
/// |
| 58 |
/// @code |
| 59 |
/// connection_options opts; |
| 60 |
/// opts.idle_timeout(1000).max_frame_size(10000); |
| 61 |
/// c1 = container.connect(url1, opts.handler(h1)); |
| 62 |
/// c2 = container.connect(url2, opts.handler(h2)); |
| 63 |
/// @endcode |
| 64 |
/// |
| 65 |
/// Normal value semantics: copy or assign creates a separate copy of |
| 66 |
/// the options. |
| 67 |
class connection_options { |
| 68 |
public: |
| 69 |
/// Create an empty set of options. |
| 70 |
PN_CPP_EXTERN connection_options(); |
| 71 |
|
| 72 |
/// Shorthand for `connection_options().handler(h)`. |
| 73 |
PN_CPP_EXTERN connection_options(class messaging_handler& h); |
| 74 |
|
| 75 |
/// Copy options. |
| 76 |
PN_CPP_EXTERN connection_options(const connection_options&); |
| 77 |
|
| 78 |
PN_CPP_EXTERN ~connection_options(); |
| 79 |
|
| 80 |
/// Copy options. |
| 81 |
PN_CPP_EXTERN connection_options& operator=(const connection_options&); |
| 82 |
|
| 83 |
// XXX add C++11 move operations - Still relevant, and applies to all options |
| 84 |
|
| 85 |
/// Set a connection handler. |
| 86 |
/// |
| 87 |
/// The handler must not be deleted until |
| 88 |
/// messaging_handler::on_transport_close() is called. |
| 89 |
PN_CPP_EXTERN connection_options& handler(class messaging_handler&); |
| 90 |
|
| 91 |
/// Set the maximum frame size. It is unlimited by default. |
| 92 |
PN_CPP_EXTERN connection_options& max_frame_size(uint32_t max); |
| 93 |
|
| 94 |
/// Set the maximum number of open sessions. The default is 32767. |
| 95 |
PN_CPP_EXTERN connection_options& max_sessions(uint16_t max); |
| 96 |
|
| 97 |
/// Set the idle timeout. The default is no timeout. |
| 98 |
/// |
| 99 |
/// If set, the local peer will disconnect if it receives no AMQP |
| 100 |
/// frames for an interval longer than `duration`. Also known as |
| 101 |
/// "heartbeating", this is a way to detect dead peers even in the |
| 102 |
/// presence of a live TCP connection. |
| 103 |
PN_CPP_EXTERN connection_options& idle_timeout(duration); |
| 104 |
|
| 105 |
/// Set the container ID. |
| 106 |
PN_CPP_EXTERN connection_options& container_id(const std::string& id); |
| 107 |
|
| 108 |
/// Set the virtual host name for the connection. For client |
| 109 |
/// connections, it defaults to the host name used to set up the |
| 110 |
/// connection. For server connections, it is unset by default. |
| 111 |
/// |
| 112 |
/// If making a client connection by SSL/TLS, this name is also |
| 113 |
/// used for certificate verification and Server Name Indication. |
| 114 |
PN_CPP_EXTERN connection_options& virtual_host(const std::string& name); |
| 115 |
|
| 116 |
/// Set the user name used to authenticate the connection. It is |
| 117 |
/// unset by default. |
| 118 |
/// |
| 119 |
/// This value overrides any user name that is specified in the |
| 120 |
/// URL used for `container::connect`. It is ignored if the |
| 121 |
/// connection is created by `container::listen` because a |
| 122 |
/// listening connection's identity is provided by the remote |
| 123 |
/// client. |
| 124 |
PN_CPP_EXTERN connection_options& user(const std::string&); |
| 125 |
|
| 126 |
/// Set the password used to authenticate the connection. |
| 127 |
/// |
| 128 |
/// This value is ignored if the connection is created by |
| 129 |
/// `container::listen`. |
| 130 |
PN_CPP_EXTERN connection_options& password(const std::string&); |
| 131 |
|
| 132 |
/// Set SSL client options. |
| 133 |
PN_CPP_EXTERN connection_options& ssl_client_options(const class ssl_client_options&); |
| 134 |
|
| 135 |
/// Set SSL server options. |
| 136 |
PN_CPP_EXTERN connection_options& ssl_server_options(const class ssl_server_options&); |
| 137 |
|
| 138 |
/// Enable or disable SASL. |
| 139 |
PN_CPP_EXTERN connection_options& sasl_enabled(bool); |
| 140 |
|
| 141 |
/// Force the enabling of SASL mechanisms that disclose cleartext |
| 142 |
/// passwords over the connection. By default, such mechanisms |
| 143 |
/// are disabled. |
| 144 |
PN_CPP_EXTERN connection_options& sasl_allow_insecure_mechs(bool); |
| 145 |
|
| 146 |
/// Specify the SASL mechanisms allowed for this connection. |
| 147 |
/// The value is a space-separated list of mechanism names. |
| 148 |
/// |
| 149 |
/// The mechanisms allowed by default are determined by your SASL |
| 150 |
/// library and system configuration, with two exceptions: GSSAPI |
| 151 |
/// and GSS-SPNEGO are disabled by default. To enable them, you |
| 152 |
/// must explicitly add them using this option. |
| 153 |
/// |
| 154 |
/// Clients must set the allowed mechanisms before the the |
| 155 |
/// outgoing connection is attempted. Servers must set them |
| 156 |
/// before the listening connection is setup. |
| 157 |
PN_CPP_EXTERN connection_options& sasl_allowed_mechs(const std::string&); |
| 158 |
|
| 159 |
/// **Unsettled API** - Extension capabilities offered to the remote peer. |
| 160 |
PN_CPP_EXTERN connection_options& offered_capabilities(const std::vector<symbol>&); |
| 161 |
|
| 162 |
/// **Unsettled API** - Extension capabilities desired from the remote peer. |
| 163 |
PN_CPP_EXTERN connection_options& desired_capabilities(const std::vector<symbol>&); |
| 164 |
|
| 165 |
/// **Unsettled API** - Connection properties. |
| 166 |
PN_CPP_EXTERN connection_options& properties(const std::map<symbol, value>&); |
| 167 |
|
| 168 |
/// **Unsettled API** - Set the SASL configuration name. |
| 169 |
PN_CPP_EXTERN connection_options& sasl_config_name(const std::string&); |
| 170 |
|
| 171 |
/// **Unsettled API** - Set the SASL configuration path. |
| 172 |
PN_CPP_EXTERN connection_options& sasl_config_path(const std::string&); |
| 173 |
|
| 174 |
/// **Unsettled API** - Set reconnect timing options. |
| 175 |
/// |
| 176 |
/// If reconnect timing options are set, but no specific reconnect or failover urls are set |
| 177 |
/// then the original url used for the connection will be used as the reconnect url. |
| 178 |
PN_CPP_EXTERN connection_options& reconnect(const reconnect_options&); |
| 179 |
|
| 180 |
/// **Unsettled API** - Set reconnect URL. |
| 181 |
/// |
| 182 |
/// If the connection to the primary connection url fails then try to reconnect using |
| 183 |
/// the reconnect url. |
| 184 |
/// |
| 185 |
/// If this option is set then it will by default set the default reconnect timing options. |
| 186 |
/// |
| 187 |
/// If this option is changed using @ref connection::update_options before a reconnection |
| 188 |
/// attempt (for example in the @ref messaging_handler::on_transport_error callback) then |
| 189 |
/// the new value of the reconnect url will be used for the reconnect attempt rather then |
| 190 |
/// any previous value. |
| 191 |
/// |
| 192 |
/// If both the failover_urls and reconnect_url options are set then the behavior is not defined. |
| 193 |
PN_CPP_EXTERN connection_options& reconnect_url(const std::string&); |
| 194 |
|
| 195 |
/// **Unsettled API** - Set Fail-over URLs. |
| 196 |
/// |
| 197 |
/// If the connection to the primary connection url fails then try each of the fail-over |
| 198 |
/// connection urls in turn. |
| 199 |
/// |
| 200 |
/// If this option is set then it will by default set the default reconnect timing options. |
| 201 |
/// |
| 202 |
/// If this option is changed using @ref connection::update_options before a reconnection |
| 203 |
/// attempt (for example in the @ref messaging_handler::on_transport_error callback) then |
| 204 |
/// the new values of the failover urls will be used for the reconnect attempt rather then |
| 205 |
/// any previous value. |
| 206 |
/// |
| 207 |
/// If both the failover_urls and reconnect_url options are set then the behavior is not defined. |
| 208 |
PN_CPP_EXTERN connection_options& failover_urls(const std::vector<std::string>&); |
| 209 |
|
| 210 |
/// Update option values from values set in other. |
| 211 |
PN_CPP_EXTERN connection_options& update(const connection_options& other); |
| 212 |
|
| 213 |
private: |
| 214 |
void apply_unbound(connection&) const; |
| 215 |
void apply_reconnect_urls(pn_connection_t* pnc) const; |
| 216 |
void apply_unbound_client(pn_transport_t*) const; |
| 217 |
void apply_unbound_server(pn_transport_t*) const; |
| 218 |
messaging_handler* handler() const; |
| 219 |
|
| 220 |
class impl; |
| 221 |
std::unique_ptr<impl> impl_; |
| 222 |
|
| 223 |
/// @cond INTERNAL |
| 224 |
friend class container; |
| 225 |
friend class io::connection_driver; |
| 226 |
friend class connection; |
| 227 |
/// @endcond |
| 228 |
}; |
| 229 |
|
| 230 |
} // proton |
| 231 |
|
| 232 |
#endif // PROTON_CONNECTION_OPTIONS_H |