1/* GIO - GLib Input, Output and Streaming Library
2 *
3 * Copyright © 2010 Red Hat, Inc.
4 * Copyright © 2015 Collabora, Ltd.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library 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 GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef __G_DTLS_CONNECTION_H__
21#define __G_DTLS_CONNECTION_H__
22
23#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
24#error "Only <gio/gio.h> can be included directly."
25#endif
26
27#include <gio/gdatagrambased.h>
28
29G_BEGIN_DECLS
30
31#define G_TYPE_DTLS_CONNECTION (g_dtls_connection_get_type ())
32#define G_DTLS_CONNECTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), G_TYPE_DTLS_CONNECTION, GDtlsConnection))
33#define G_IS_DTLS_CONNECTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_DTLS_CONNECTION))
34#define G_DTLS_CONNECTION_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), G_TYPE_DTLS_CONNECTION, GDtlsConnectionInterface))
35
36typedef struct _GDtlsConnectionInterface GDtlsConnectionInterface;
37
38/**
39 * GDtlsConnectionInterface:
40 * @g_iface: The parent interface.
41 * @accept_certificate: Check whether to accept a certificate.
42 * @handshake: Perform a handshake operation.
43 * @handshake_async: Start an asynchronous handshake operation.
44 * @handshake_finish: Finish an asynchronous handshake operation.
45 * @shutdown: Shut down one or both directions of the connection.
46 * @shutdown_async: Start an asynchronous shutdown operation.
47 * @shutdown_finish: Finish an asynchronous shutdown operation.
48 * @set_advertised_protocols: Set APLN protocol list
49 * @get_negotiated_protocol: Retrieve ALPN-negotiated protocol
50 *
51 * Virtual method table for a #GDtlsConnection implementation.
52 *
53 * Since: 2.48
54 */
55struct _GDtlsConnectionInterface
56{
57 GTypeInterface g_iface;
58
59 /* signals */
60 gboolean (*accept_certificate) (GDtlsConnection *connection,
61 GTlsCertificate *peer_cert,
62 GTlsCertificateFlags errors);
63
64 /* methods */
65 gboolean (*handshake) (GDtlsConnection *conn,
66 GCancellable *cancellable,
67 GError **error);
68
69 void (*handshake_async) (GDtlsConnection *conn,
70 int io_priority,
71 GCancellable *cancellable,
72 GAsyncReadyCallback callback,
73 gpointer user_data);
74 gboolean (*handshake_finish) (GDtlsConnection *conn,
75 GAsyncResult *result,
76 GError **error);
77
78 gboolean (*shutdown) (GDtlsConnection *conn,
79 gboolean shutdown_read,
80 gboolean shutdown_write,
81 GCancellable *cancellable,
82 GError **error);
83
84 void (*shutdown_async) (GDtlsConnection *conn,
85 gboolean shutdown_read,
86 gboolean shutdown_write,
87 int io_priority,
88 GCancellable *cancellable,
89 GAsyncReadyCallback callback,
90 gpointer user_data);
91 gboolean (*shutdown_finish) (GDtlsConnection *conn,
92 GAsyncResult *result,
93 GError **error);
94
95 void (*set_advertised_protocols) (GDtlsConnection *conn,
96 const gchar * const *protocols);
97 const gchar *(*get_negotiated_protocol) (GDtlsConnection *conn);
98};
99
100GLIB_AVAILABLE_IN_2_48
101GType g_dtls_connection_get_type (void) G_GNUC_CONST;
102
103GLIB_AVAILABLE_IN_2_48
104void g_dtls_connection_set_database (GDtlsConnection *conn,
105 GTlsDatabase *database);
106GLIB_AVAILABLE_IN_2_48
107GTlsDatabase *g_dtls_connection_get_database (GDtlsConnection *conn);
108
109GLIB_AVAILABLE_IN_2_48
110void g_dtls_connection_set_certificate (GDtlsConnection *conn,
111 GTlsCertificate *certificate);
112GLIB_AVAILABLE_IN_2_48
113GTlsCertificate *g_dtls_connection_get_certificate (GDtlsConnection *conn);
114
115GLIB_AVAILABLE_IN_2_48
116void g_dtls_connection_set_interaction (GDtlsConnection *conn,
117 GTlsInteraction *interaction);
118GLIB_AVAILABLE_IN_2_48
119GTlsInteraction *g_dtls_connection_get_interaction (GDtlsConnection *conn);
120
121GLIB_AVAILABLE_IN_2_48
122GTlsCertificate *g_dtls_connection_get_peer_certificate (GDtlsConnection *conn);
123GLIB_AVAILABLE_IN_2_48
124GTlsCertificateFlags g_dtls_connection_get_peer_certificate_errors (GDtlsConnection *conn);
125
126GLIB_AVAILABLE_IN_2_48
127void g_dtls_connection_set_require_close_notify (GDtlsConnection *conn,
128 gboolean require_close_notify);
129GLIB_AVAILABLE_IN_2_48
130gboolean g_dtls_connection_get_require_close_notify (GDtlsConnection *conn);
131
132G_GNUC_BEGIN_IGNORE_DEPRECATIONS
133GLIB_DEPRECATED_IN_2_60
134void g_dtls_connection_set_rehandshake_mode (GDtlsConnection *conn,
135 GTlsRehandshakeMode mode);
136GLIB_DEPRECATED_IN_2_60
137GTlsRehandshakeMode g_dtls_connection_get_rehandshake_mode (GDtlsConnection *conn);
138G_GNUC_END_IGNORE_DEPRECATIONS
139
140GLIB_AVAILABLE_IN_2_48
141gboolean g_dtls_connection_handshake (GDtlsConnection *conn,
142 GCancellable *cancellable,
143 GError **error);
144
145GLIB_AVAILABLE_IN_2_48
146void g_dtls_connection_handshake_async (GDtlsConnection *conn,
147 int io_priority,
148 GCancellable *cancellable,
149 GAsyncReadyCallback callback,
150 gpointer user_data);
151GLIB_AVAILABLE_IN_2_48
152gboolean g_dtls_connection_handshake_finish (GDtlsConnection *conn,
153 GAsyncResult *result,
154 GError **error);
155
156GLIB_AVAILABLE_IN_2_48
157gboolean g_dtls_connection_shutdown (GDtlsConnection *conn,
158 gboolean shutdown_read,
159 gboolean shutdown_write,
160 GCancellable *cancellable,
161 GError **error);
162
163GLIB_AVAILABLE_IN_2_48
164void g_dtls_connection_shutdown_async (GDtlsConnection *conn,
165 gboolean shutdown_read,
166 gboolean shutdown_write,
167 int io_priority,
168 GCancellable *cancellable,
169 GAsyncReadyCallback callback,
170 gpointer user_data);
171GLIB_AVAILABLE_IN_2_48
172gboolean g_dtls_connection_shutdown_finish (GDtlsConnection *conn,
173 GAsyncResult *result,
174 GError **error);
175
176GLIB_AVAILABLE_IN_2_48
177gboolean g_dtls_connection_close (GDtlsConnection *conn,
178 GCancellable *cancellable,
179 GError **error);
180
181GLIB_AVAILABLE_IN_2_48
182void g_dtls_connection_close_async (GDtlsConnection *conn,
183 int io_priority,
184 GCancellable *cancellable,
185 GAsyncReadyCallback callback,
186 gpointer user_data);
187GLIB_AVAILABLE_IN_2_48
188gboolean g_dtls_connection_close_finish (GDtlsConnection *conn,
189 GAsyncResult *result,
190 GError **error);
191
192/*< protected >*/
193GLIB_AVAILABLE_IN_2_48
194gboolean g_dtls_connection_emit_accept_certificate (GDtlsConnection *conn,
195 GTlsCertificate *peer_cert,
196 GTlsCertificateFlags errors);
197GLIB_AVAILABLE_IN_2_60
198void g_dtls_connection_set_advertised_protocols (GDtlsConnection *conn,
199 const gchar * const *protocols);
200
201GLIB_AVAILABLE_IN_2_60
202const gchar * g_dtls_connection_get_negotiated_protocol (GDtlsConnection *conn);
203
204G_END_DECLS
205
206#endif /* __G_DTLS_CONNECTION_H__ */
207