Debian Codegraph @

c/include/proton/connection.h

raw
1 #ifndef PROTON_CONNECTION_H
2 #define PROTON_CONNECTION_H 1
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 <proton/import_export.h>
26 #include <proton/codec.h>
27 #include <proton/condition.h>
28 #include <proton/error.h>
29 #include <proton/type_compat.h>
30 #include <proton/types.h>
31
32 #include <stddef.h>
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 /**
39 * @file
40 *
41 * @copybrief connection
42 *
43 * @addtogroup connection
44 * @{
45 */
46
47 /**
48 * The local @link pn_state_t endpoint state @endlink is uninitialized.
49 */
50 #define PN_LOCAL_UNINIT (1)
51
52 /**
53 * The local @link pn_state_t endpoint state @endlink is active.
54 */
55 #define PN_LOCAL_ACTIVE (2)
56
57 /**
58 * The local @link pn_state_t endpoint state @endlink is closed.
59 */
60 #define PN_LOCAL_CLOSED (4)
61
62 /**
63 * The remote @link pn_state_t endpoint state @endlink is uninitialized.
64 */
65 #define PN_REMOTE_UNINIT (8)
66
67 /**
68 * The remote @link pn_state_t endpoint state @endlink is active.
69 */
70 #define PN_REMOTE_ACTIVE (16)
71
72 /**
73 * The remote @link pn_state_t endpoint state @endlink is closed.
74 */
75 #define PN_REMOTE_CLOSED (32)
76
77 /**
78 * A mask for values of ::pn_state_t that preserves only the local
79 * bits of an endpoint's state.
80 */
81 #define PN_LOCAL_MASK (PN_LOCAL_UNINIT | PN_LOCAL_ACTIVE | PN_LOCAL_CLOSED)
82
83 /**
84 * A mask for values of ::pn_state_t that preserves only the remote
85 * bits of an endpoint's state.
86 */
87 #define PN_REMOTE_MASK (PN_REMOTE_UNINIT | PN_REMOTE_ACTIVE | PN_REMOTE_CLOSED)
88
89 PN_EXTERN pn_connection_t *pn_connection(void);
90
91 /**
92 * Factory to construct a new Connection.
93 *
94 * @return pointer to a new connection object.
95 */
96 PN_EXTERN pn_connection_t *pn_connection(void);
97
98 /**
99 * Free a connection object.
100 *
101 * When a connection object is freed, all ::pn_session_t, ::pn_link_t,
102 * and ::pn_delivery_t objects associated with the connection are also
103 * freed.
104 *
105 * @param[in] connection the connection object to free (or NULL)
106 */
107 PN_EXTERN void pn_connection_free(pn_connection_t *connection);
108
109 /**
110 * Release a connection object.
111 *
112 * When a connection object is released, all ::pn_session_t and
113 * ::pn_link_t, objects associated with the connection are also
114 * released and all ::pn_delivery_t objects are settled.
115 *
116 * @param[in] connection the connection object to be released
117 */
118 PN_EXTERN void pn_connection_release(pn_connection_t *connection);
119
120 /**
121 * **Deprecated** - Use ::pn_connection_condition().
122 *
123 * Get additional error information associated with the connection.
124 *
125 * Whenever a connection operation fails (i.e. returns an error code),
126 * additional error details can be obtained using this function. The
127 * error object that is returned may also be used to clear the error
128 * condition.
129 *
130 * The pointer returned by this operation is valid until the
131 * connection object is freed.
132 *
133 * Deprecation notice: note that this will always return an empty
134 * error object
135 *
136 * @param[in] connection the connection object
137 * @return the connection's error object
138 */
139 /* PN_DEPRECATED("Use pn_connection_condition") */
140 PN_EXTERN pn_error_t *pn_connection_error(pn_connection_t *connection);
141
142 /**
143 * Associate a connection object with an event collector.
144 *
145 * By associating a connection object with an event collector, key
146 * changes in endpoint state are reported to the collector via
147 * ::pn_event_t objects that can be inspected and processed. See
148 * ::pn_event_t for more details on the kinds of events.
149 *
150 * Note that by registering a collector, the user is requesting that
151 * an indefinite number of events be queued up on his behalf. This
152 * means that unless the application eventually processes these
153 * events, the storage requirements for keeping them will grow without
154 * bound. In other words, don't register a collector with a connection
155 * if you never intend to process any of the events.
156 *
157 * @param[in] connection the connection object
158 * @param[in] collector the event collector
159 */
160 PN_EXTERN void pn_connection_collect(pn_connection_t *connection, pn_collector_t *collector);
161
162 /**
163 * Get the collector set with pn_connection_collect()
164 * @return NULL if pn_connection_collect() has not been called.
165 */
166 PN_EXTERN pn_collector_t* pn_connection_collector(pn_connection_t *connection);
167
168 /**
169 * Get the application context that is associated with a connection
170 * object.
171 *
172 * The application context for a connection may be set using
173 * ::pn_connection_set_context.
174 *
175 * @param[in] connection the connection whose context is to be returned.
176 * @return the application context for the connection object
177 */
178 PN_EXTERN void *pn_connection_get_context(pn_connection_t *connection);
179
180 /**
181 * Set a new application context for a connection object.
182 *
183 * The application context for a connection object may be retrieved
184 * using ::pn_connection_get_context.
185 *
186 * @param[in] connection the connection object
187 * @param[in] context the application context
188 */
189 PN_EXTERN void pn_connection_set_context(pn_connection_t *connection, void *context);
190
191 /**
192 * Get the attachments that are associated with a connection object.
193 *
194 * @param[in] connection the connection whose attachments are to be returned.
195 * @return the attachments for the connection object
196 */
197 PN_EXTERN pn_record_t *pn_connection_attachments(pn_connection_t *connection);
198
199 /**
200 * Get the endpoint state flags for a connection.
201 *
202 * @param[in] connection the connection
203 * @return the connection's state flags
204 */
205 PN_EXTERN pn_state_t pn_connection_state(pn_connection_t *connection);
206
207 /**
208 * Open a connection.
209 *
210 * Once this operation has completed, the PN_LOCAL_ACTIVE state flag
211 * will be set.
212 *
213 * @param[in] connection the connection object
214 */
215 PN_EXTERN void pn_connection_open(pn_connection_t *connection);
216
217 /**
218 * Close a connection.
219 *
220 * Once this operation has completed, the PN_LOCAL_CLOSED state flag
221 * will be set. This may be called without calling
222 * ::pn_connection_open, in this case it is equivalent to calling
223 * ::pn_connection_open followed by ::pn_connection_close.
224 *
225 * @param[in] connection the connection object
226 */
227 PN_EXTERN void pn_connection_close(pn_connection_t *connection);
228
229 /**
230 * Reset a connection object back to the uninitialized state.
231 *
232 * Note that this does *not* remove any contained ::pn_session_t,
233 * ::pn_link_t, and ::pn_delivery_t objects.
234 *
235 * @param[in] connection the connection object
236 */
237 PN_EXTERN void pn_connection_reset(pn_connection_t *connection);
238
239 /**
240 * Get the local condition associated with the connection endpoint.
241 *
242 * The ::pn_condition_t object retrieved may be modified prior to
243 * closing the connection in order to indicate a particular condition
244 * exists when the connection closes. This is normally used to
245 * communicate error conditions to the remote peer, however it may
246 * also be used in non error cases such as redirects. See
247 * ::pn_condition_t for more details.
248 *
249 * The pointer returned by this operation is valid until the
250 * connection object is freed.
251 *
252 * @param[in] connection the connection object
253 * @return the connection's local condition object
254 */
255 PN_EXTERN pn_condition_t *pn_connection_condition(pn_connection_t *connection);
256
257 /**
258 * Get the remote condition associated with the connection endpoint.
259 *
260 * The ::pn_condition_t object retrieved may be examined in order to
261 * determine whether the remote peer was indicating some sort of
262 * exceptional condition when the remote connection endpoint was
263 * closed. The ::pn_condition_t object returned may not be modified.
264 *
265 * The pointer returned by this operation is valid until the
266 * connection object is freed.
267 *
268 * @param[in] connection the connection object
269 * @return the connection's remote condition object
270 */
271 PN_EXTERN pn_condition_t *pn_connection_remote_condition(pn_connection_t *connection);
272
273 /**
274 * Get the AMQP Container name advertised by a connection object.
275 *
276 * The pointer returned by this operation is valid until
277 * ::pn_connection_set_container is called, or until the connection
278 * object is freed, whichever happens sooner.
279 *
280 * @param[in] connection the connection object
281 * @return a pointer to the container name
282 */
283 PN_EXTERN const char *pn_connection_get_container(pn_connection_t *connection);
284
285 /**
286 * Set the AMQP Container name advertised by a connection object.
287 *
288 * @param[in] connection the connection object
289 * @param[in] container the container name
290 */
291 PN_EXTERN void pn_connection_set_container(pn_connection_t *connection, const char *container);
292
293 /**
294 * Set the authentication username for a client connection
295 *
296 * It is necessary to set the username and password before binding the connection
297 * to a transport and it isn't allowed to change them after the binding.
298 *
299 * If not set then no authentication will be negotiated unless the client
300 * sasl layer is explicitly created (this would be for something like Kerberos
301 * where the credentials are implicit in the environment, or to explicitly use
302 * the ANONYMOUS SASL mechanism)
303 *
304 * @param[in] connection the connection
305 * @param[in] user the username
306 */
307 PN_EXTERN void pn_connection_set_user(pn_connection_t *connection, const char *user);
308
309 /**
310 * Set the authentication password for a client connection
311 *
312 * It is necessary to set the username and password before binding the connection
313 * to a transport and it isn't allowed to change them after the binding.
314 *
315 * Note that the password is write only and has no accessor as the underlying
316 * implementation should be zeroing the password after use to avoid the password
317 * being present in memory longer than necessary
318 *
319 * @param[in] connection the connection
320 * @param[in] password the password corresponding to the username - this will be copied and zeroed out after use
321 */
322 PN_EXTERN void pn_connection_set_password(pn_connection_t *connection, const char *password);
323
324 /**
325 * Set the authorization id for a client connection
326 *
327 * It is necessary to set the authorization before binding the connection
328 * to a transport and it isn't allowed to change it after the binding.
329 *
330 * This is only useful if the negotiated sasl mechanism supports transporting an authorization id separate from
331 * the authentication user.
332 *
333 * By default all mechanisms will consider the requested authorization as identical to the authentication if it
334 * is not supplied.
335 *
336 * @param[in] connection the connection
337 * @param[in] authzid the authorization id
338 */
339 PN_EXTERN void pn_connection_set_authorization(pn_connection_t *connection, const char *authzid);
340
341 /**
342 * Get the authentication username for a client connection
343 *
344 * @param[in] connection the connection
345 * @return the username passed into the connection
346 */
347 PN_EXTERN const char *pn_connection_get_user(pn_connection_t *connection);
348
349 /**
350 * Get the authorization id for a client connection
351 *
352 * @param[in] connection the connection
353 * @return the authorization passed into the connection
354 */
355 PN_EXTERN const char *pn_connection_get_authorization(pn_connection_t *connection);
356
357 /**
358 * Get the value of the AMQP Hostname used by a connection object.
359 *
360 * The pointer returned by this operation is valid until
361 * ::pn_connection_set_hostname is called, or until the connection
362 * object is freed, whichever happens sooner.
363 *
364 * @param[in] connection the connection object
365 * @return a pointer to the hostname
366 */
367 PN_EXTERN const char *pn_connection_get_hostname(pn_connection_t *connection);
368
369 /**
370 * Set the name of the virtual host (either fully qualified or relative) to
371 * which this connection is connecting to. This information may be used by the
372 * remote peer to determine the correct back-end service to connect the client
373 * to. This value will be sent in the Open performative, and will be used by
374 * SSL and SASL layers to identify the peer.
375 *
376 * @note Note: the virtual host string is passed verbatim, it is not parsed as
377 * a URL or modified in any way. It should not contain numeric IP addresses or
378 * port numbers unless that is what you intend to send as the virtual host name
379 * @param[in] connection the connection object
380 * @param[in] hostname the virtual host name
381 */
382 PN_EXTERN void pn_connection_set_hostname(pn_connection_t *connection, const char *hostname);
383
384 /**
385 * Get the AMQP Container name advertised by the remote connection
386 * endpoint.
387 *
388 * This will return NULL until the ::PN_REMOTE_ACTIVE state is
389 * reached. See ::pn_state_t for more details on endpoint state.
390 *
391 * Any non null pointer returned by this operation will be valid until
392 * the connection object is unbound from a transport or freed,
393 * whichever happens sooner.
394 *
395 * @param[in] connection the connection object
396 * @return a pointer to the remote container name
397 */
398 PN_EXTERN const char *pn_connection_remote_container(pn_connection_t *connection);
399
400 /**
401 * Get the AMQP Hostname set by the remote connection endpoint.
402 *
403 * This will return NULL until the ::PN_REMOTE_ACTIVE state is
404 * reached. See ::pn_state_t for more details on endpoint state.
405 *
406 * Any non null pointer returned by this operation will be valid until
407 * the connection object is unbound from a transport or freed,
408 * whichever happens sooner.
409 *
410 * @param[in] connection the connection object
411 * @return a pointer to the remote hostname
412 */
413 PN_EXTERN const char *pn_connection_remote_hostname(pn_connection_t *connection);
414
415 /**
416 * Access/modify the AMQP offered capabilities data for a connection
417 * object.
418 *
419 * This operation will return a pointer to a ::pn_data_t object that
420 * is valid until the connection object is freed. Any data contained
421 * by the ::pn_data_t object will be sent as the offered capabilities
422 * for the parent connection object. Note that this MUST take the form
423 * of an array of symbols to be valid.
424 *
425 * The ::pn_data_t pointer returned is valid until the connection
426 * object is freed.
427 *
428 * @param[in] connection the connection object
429 * @return a pointer to a pn_data_t representing the offered capabilities
430 */
431 PN_EXTERN pn_data_t *pn_connection_offered_capabilities(pn_connection_t *connection);
432
433 /**
434 * Access/modify the AMQP desired capabilities data for a connection
435 * object.
436 *
437 * This operation will return a pointer to a ::pn_data_t object that
438 * is valid until the connection object is freed. Any data contained
439 * by the ::pn_data_t object will be sent as the desired capabilities
440 * for the parent connection object. Note that this MUST take the form
441 * of an array of symbols to be valid.
442 *
443 * The ::pn_data_t pointer returned is valid until the connection
444 * object is freed.
445 *
446 * @param[in] connection the connection object
447 * @return a pointer to a pn_data_t representing the desired capabilities
448 */
449 PN_EXTERN pn_data_t *pn_connection_desired_capabilities(pn_connection_t *connection);
450
451 /**
452 * Access/modify the AMQP properties data for a connection object.
453 *
454 * This operation will return a pointer to a ::pn_data_t object that
455 * is valid until the connection object is freed. Any data contained
456 * by the ::pn_data_t object will be sent as the AMQP properties for
457 * the parent connection object. Note that this MUST take the form of
458 * a symbol keyed map to be valid.
459 *
460 * The ::pn_data_t pointer returned is valid until the connection
461 * object is freed.
462 *
463 * @param[in] connection the connection object
464 * @return a pointer to a pn_data_t representing the connection properties
465 */
466 PN_EXTERN pn_data_t *pn_connection_properties(pn_connection_t *connection);
467
468 /**
469 * Access the AMQP offered capabilities supplied by the remote
470 * connection endpoint.
471 *
472 * This operation will return a pointer to a ::pn_data_t object that
473 * is valid until the connection object is freed. This data object
474 * will be empty until the remote connection is opened as indicated by
475 * the ::PN_REMOTE_ACTIVE flag.
476 *
477 * @param[in] connection the connection object
478 * @return the remote offered capabilities
479 */
480 PN_EXTERN pn_data_t *pn_connection_remote_offered_capabilities(pn_connection_t *connection);
481
482 /**
483 * Access the AMQP desired capabilities supplied by the remote
484 * connection endpoint.
485 *
486 * This operation will return a pointer to a ::pn_data_t object that
487 * is valid until the connection object is freed. This data object
488 * will be empty until the remote connection is opened as indicated by
489 * the ::PN_REMOTE_ACTIVE flag.
490 *
491 * @param[in] connection the connection object
492 * @return the remote desired capabilities
493 */
494 PN_EXTERN pn_data_t *pn_connection_remote_desired_capabilities(pn_connection_t *connection);
495
496 /**
497 * Access the AMQP connection properties supplied by the remote
498 * connection endpoint.
499 *
500 * This operation will return a pointer to a ::pn_data_t object that
501 * is valid until the connection object is freed. This data object
502 * will be empty until the remote connection is opened as indicated by
503 * the ::PN_REMOTE_ACTIVE flag.
504 *
505 * @param[in] connection the connection object
506 * @return the remote connection properties
507 */
508 PN_EXTERN pn_data_t *pn_connection_remote_properties(pn_connection_t *connection);
509
510 /**
511 * Get the transport bound to a connection object.
512 *
513 * If the connection is unbound, then this operation will return NULL.
514 *
515 * @param[in] connection the connection object
516 * @return the transport bound to a connection, or NULL if the
517 * connection is unbound
518 */
519 PN_EXTERN pn_transport_t *pn_connection_transport(pn_connection_t *connection);
520
521 /**
522 * @}
523 */
524
525 #ifdef __cplusplus
526 }
527 #endif
528
529 #endif /* connection.h */