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 | #include "config.h" |
21 | #include "glib.h" |
22 | |
23 | #include "gdtlsserverconnection.h" |
24 | #include "ginitable.h" |
25 | #include "gioenumtypes.h" |
26 | #include "gsocket.h" |
27 | #include "gtlsbackend.h" |
28 | #include "gtlscertificate.h" |
29 | #include "glibintl.h" |
30 | |
31 | /** |
32 | * SECTION:gdtlsserverconnection |
33 | * @short_description: DTLS server-side connection |
34 | * @include: gio/gio.h |
35 | * |
36 | * #GDtlsServerConnection is the server-side subclass of #GDtlsConnection, |
37 | * representing a server-side DTLS connection. |
38 | * |
39 | * Since: 2.48 |
40 | */ |
41 | |
42 | G_DEFINE_INTERFACE (GDtlsServerConnection, g_dtls_server_connection, |
43 | G_TYPE_DTLS_CONNECTION) |
44 | |
45 | static void |
46 | g_dtls_server_connection_default_init (GDtlsServerConnectionInterface *iface) |
47 | { |
48 | /** |
49 | * GDtlsServerConnection:authentication-mode: |
50 | * |
51 | * The #GTlsAuthenticationMode for the server. This can be changed |
52 | * before calling g_dtls_connection_handshake() if you want to |
53 | * rehandshake with a different mode from the initial handshake. |
54 | * |
55 | * Since: 2.48 |
56 | */ |
57 | g_object_interface_install_property (g_iface: iface, |
58 | pspec: g_param_spec_enum (name: "authentication-mode" , |
59 | P_("Authentication Mode" ), |
60 | P_("The client authentication mode" ), |
61 | enum_type: G_TYPE_TLS_AUTHENTICATION_MODE, |
62 | default_value: G_TLS_AUTHENTICATION_NONE, |
63 | flags: G_PARAM_READWRITE | |
64 | G_PARAM_STATIC_STRINGS)); |
65 | } |
66 | |
67 | /** |
68 | * g_dtls_server_connection_new: |
69 | * @base_socket: the #GDatagramBased to wrap |
70 | * @certificate: (nullable): the default server certificate, or %NULL |
71 | * @error: #GError for error reporting, or %NULL to ignore |
72 | * |
73 | * Creates a new #GDtlsServerConnection wrapping @base_socket. |
74 | * |
75 | * Returns: (transfer full) (type GDtlsServerConnection): the new |
76 | * #GDtlsServerConnection, or %NULL on error |
77 | * |
78 | * Since: 2.48 |
79 | */ |
80 | GDatagramBased * |
81 | g_dtls_server_connection_new (GDatagramBased *base_socket, |
82 | GTlsCertificate *certificate, |
83 | GError **error) |
84 | { |
85 | GObject *conn; |
86 | GTlsBackend *backend; |
87 | |
88 | backend = g_tls_backend_get_default (); |
89 | conn = g_initable_new (object_type: g_tls_backend_get_dtls_server_connection_type (backend), |
90 | NULL, error, |
91 | first_property_name: "base-socket" , base_socket, |
92 | "certificate" , certificate, |
93 | NULL); |
94 | return G_DATAGRAM_BASED (conn); |
95 | } |
96 | |