Coverage Report

Created: 2025-06-13 06:55

/src/glib/gio/gdtlsserverconnection.c
Line
Count
Source (jump to first uncovered line)
1
/* GIO - GLib Input, Output and Streaming Library
2
 *
3
 * Copyright © 2010 Red Hat, Inc
4
 * Copyright © 2015 Collabora, Ltd.
5
 *
6
 * SPDX-License-Identifier: LGPL-2.1-or-later
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General
19
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#include "config.h"
23
#include "glib.h"
24
25
#include "gdtlsserverconnection.h"
26
#include "ginitable.h"
27
#include "gioenumtypes.h"
28
#include "gsocket.h"
29
#include "gtlsbackend.h"
30
#include "gtlscertificate.h"
31
#include "glibintl.h"
32
33
/**
34
 * SECTION:gdtlsserverconnection
35
 * @short_description: DTLS server-side connection
36
 * @include: gio/gio.h
37
 *
38
 * #GDtlsServerConnection is the server-side subclass of #GDtlsConnection,
39
 * representing a server-side DTLS connection.
40
 *
41
 * Since: 2.48
42
 */
43
44
G_DEFINE_INTERFACE (GDtlsServerConnection, g_dtls_server_connection,
45
                    G_TYPE_DTLS_CONNECTION)
46
47
static void
48
g_dtls_server_connection_default_init (GDtlsServerConnectionInterface *iface)
49
0
{
50
  /**
51
   * GDtlsServerConnection:authentication-mode:
52
   *
53
   * The #GTlsAuthenticationMode for the server. This can be changed
54
   * before calling g_dtls_connection_handshake() if you want to
55
   * rehandshake with a different mode from the initial handshake.
56
   *
57
   * Since: 2.48
58
   */
59
0
  g_object_interface_install_property (iface,
60
0
                                       g_param_spec_enum ("authentication-mode",
61
0
                                                          P_("Authentication Mode"),
62
0
                                                          P_("The client authentication mode"),
63
0
                                                          G_TYPE_TLS_AUTHENTICATION_MODE,
64
0
                                                          G_TLS_AUTHENTICATION_NONE,
65
0
                                                          G_PARAM_READWRITE |
66
0
                                                          G_PARAM_STATIC_STRINGS));
67
0
}
68
69
/**
70
 * g_dtls_server_connection_new:
71
 * @base_socket: the #GDatagramBased to wrap
72
 * @certificate: (nullable): the default server certificate, or %NULL
73
 * @error: #GError for error reporting, or %NULL to ignore
74
 *
75
 * Creates a new #GDtlsServerConnection wrapping @base_socket.
76
 *
77
 * Returns: (transfer full) (type GDtlsServerConnection): the new
78
 *   #GDtlsServerConnection, or %NULL on error
79
 *
80
 * Since: 2.48
81
 */
82
GDatagramBased *
83
g_dtls_server_connection_new (GDatagramBased   *base_socket,
84
                              GTlsCertificate  *certificate,
85
                              GError          **error)
86
0
{
87
0
  GObject *conn;
88
0
  GTlsBackend *backend;
89
90
0
  backend = g_tls_backend_get_default ();
91
0
  conn = g_initable_new (g_tls_backend_get_dtls_server_connection_type (backend),
92
0
                         NULL, error,
93
0
                         "base-socket", base_socket,
94
0
                         "certificate", certificate,
95
0
                         NULL);
96
0
  return G_DATAGRAM_BASED (conn);
97
0
}