tls: Make g_tls_{client|server}_connection_new() return a GIOStream
[platform/upstream/glib.git] / gio / gtlsserverconnection.c
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 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, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include "config.h"
22 #include "glib.h"
23
24 #include "gtlsserverconnection.h"
25 #include "ginitable.h"
26 #include "gio-marshal.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:gtlsserverconnection
35  * @short_description: TLS server-side connection
36  * @include: gio/gio.h
37  *
38  * #GTlsServerConnection is the server-side subclass of #GTlsConnection,
39  * representing a server-side TLS connection.
40  *
41  * Since: 2.28
42  */
43
44 G_DEFINE_INTERFACE (GTlsServerConnection, g_tls_server_connection, G_TYPE_TLS_CONNECTION)
45
46 static void
47 g_tls_server_connection_default_init (GTlsServerConnectionInterface *iface)
48 {
49   /**
50    * GTlsServerConnection:authentication-mode:
51    *
52    * The #GTlsAuthenticationMode for the server. This can be changed
53    * before calling g_tls_connection_handshake() if you want to
54    * rehandshake with a different mode from the initial handshake.
55    *
56    * Since: 2.28
57    */
58   g_object_interface_install_property (iface,
59                                        g_param_spec_enum ("authentication-mode",
60                                                           P_("Authentication Mode"),
61                                                           P_("The client authentication mode"),
62                                                           G_TYPE_TLS_AUTHENTICATION_MODE,
63                                                           G_TLS_AUTHENTICATION_NONE,
64                                                           G_PARAM_READWRITE |
65                                                           G_PARAM_STATIC_STRINGS));
66 }
67
68 /**
69  * g_tls_server_connection_new:
70  * @base_io_stream: the #GIOStream to wrap
71  * @certificate: (allow-none): the default server certificate, or %NULL
72  * @error: #GError for error reporting, or %NULL to ignore.
73  *
74  * Creates a new #GTlsServerConnection wrapping @base_io_stream (which
75  * must have pollable input and output streams).
76  *
77  * Return value: the new #GTlsServerConnection, or %NULL on error
78  *
79  * Since: 2.28
80  */
81 GIOStream *
82 g_tls_server_connection_new (GIOStream        *base_io_stream,
83                              GTlsCertificate  *certificate,
84                              GError          **error)
85 {
86   GObject *conn;
87   GTlsBackend *backend;
88
89   backend = g_tls_backend_get_default ();
90   conn = g_initable_new (g_tls_backend_get_server_connection_type (backend),
91                          NULL, error,
92                          "base-io-stream", base_io_stream,
93                          "certificate", certificate,
94                          NULL);
95   return G_IO_STREAM (conn);
96 }