1 | /* GIO - GLib Input, Output and Streaming Library |
2 | * |
3 | * Copyright © 2010 Red Hat, Inc |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Lesser General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2.1 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Lesser General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Lesser General |
16 | * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
17 | */ |
18 | |
19 | #include "config.h" |
20 | #include "glib.h" |
21 | |
22 | #include "gtlsserverconnection.h" |
23 | #include "ginitable.h" |
24 | #include "gioenumtypes.h" |
25 | #include "gsocket.h" |
26 | #include "gtlsbackend.h" |
27 | #include "gtlscertificate.h" |
28 | #include "glibintl.h" |
29 | |
30 | /** |
31 | * SECTION:gtlsserverconnection |
32 | * @short_description: TLS server-side connection |
33 | * @include: gio/gio.h |
34 | * |
35 | * #GTlsServerConnection is the server-side subclass of #GTlsConnection, |
36 | * representing a server-side TLS connection. |
37 | * |
38 | * Since: 2.28 |
39 | */ |
40 | |
41 | G_DEFINE_INTERFACE (GTlsServerConnection, g_tls_server_connection, G_TYPE_TLS_CONNECTION) |
42 | |
43 | static void |
44 | g_tls_server_connection_default_init (GTlsServerConnectionInterface *iface) |
45 | { |
46 | /** |
47 | * GTlsServerConnection:authentication-mode: |
48 | * |
49 | * The #GTlsAuthenticationMode for the server. This can be changed |
50 | * before calling g_tls_connection_handshake() if you want to |
51 | * rehandshake with a different mode from the initial handshake. |
52 | * |
53 | * Since: 2.28 |
54 | */ |
55 | g_object_interface_install_property (g_iface: iface, |
56 | pspec: g_param_spec_enum (name: "authentication-mode" , |
57 | P_("Authentication Mode" ), |
58 | P_("The client authentication mode" ), |
59 | enum_type: G_TYPE_TLS_AUTHENTICATION_MODE, |
60 | default_value: G_TLS_AUTHENTICATION_NONE, |
61 | flags: G_PARAM_READWRITE | |
62 | G_PARAM_STATIC_STRINGS)); |
63 | } |
64 | |
65 | /** |
66 | * g_tls_server_connection_new: |
67 | * @base_io_stream: the #GIOStream to wrap |
68 | * @certificate: (nullable): the default server certificate, or %NULL |
69 | * @error: #GError for error reporting, or %NULL to ignore. |
70 | * |
71 | * Creates a new #GTlsServerConnection wrapping @base_io_stream (which |
72 | * must have pollable input and output streams). |
73 | * |
74 | * See the documentation for #GTlsConnection:base-io-stream for restrictions |
75 | * on when application code can run operations on the @base_io_stream after |
76 | * this function has returned. |
77 | * |
78 | * Returns: (transfer full) (type GTlsServerConnection): the new |
79 | * #GTlsServerConnection, or %NULL on error |
80 | * |
81 | * Since: 2.28 |
82 | */ |
83 | GIOStream * |
84 | g_tls_server_connection_new (GIOStream *base_io_stream, |
85 | GTlsCertificate *certificate, |
86 | GError **error) |
87 | { |
88 | GObject *conn; |
89 | GTlsBackend *backend; |
90 | |
91 | backend = g_tls_backend_get_default (); |
92 | conn = g_initable_new (object_type: g_tls_backend_get_server_connection_type (backend), |
93 | NULL, error, |
94 | first_property_name: "base-io-stream" , base_io_stream, |
95 | "certificate" , certificate, |
96 | NULL); |
97 | return G_IO_STREAM (conn); |
98 | } |
99 | |