(root)/
glib-2.79.0/
gio/
gtlsserverconnection.c
       1  /* GIO - GLib Input, Output and Streaming Library
       2   *
       3   * Copyright © 2010 Red Hat, Inc
       4   *
       5   * SPDX-License-Identifier: LGPL-2.1-or-later
       6   *
       7   * This library is free software; you can redistribute it and/or
       8   * modify it under the terms of the GNU Lesser General Public
       9   * License as published by the Free Software Foundation; either
      10   * version 2.1 of the License, or (at your option) any later version.
      11   *
      12   * This library is distributed in the hope that it will be useful,
      13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15   * Lesser General Public License for more details.
      16   *
      17   * You should have received a copy of the GNU Lesser General
      18   * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
      19   */
      20  
      21  #include "config.h"
      22  #include "glib.h"
      23  
      24  #include "gtlsserverconnection.h"
      25  #include "ginitable.h"
      26  #include "gioenumtypes.h"
      27  #include "gsocket.h"
      28  #include "gtlsbackend.h"
      29  #include "gtlscertificate.h"
      30  #include "glibintl.h"
      31  
      32  /**
      33   * GTlsServerConnection:
      34   *
      35   * `GTlsServerConnection` is the server-side subclass of
      36   * [class@Gio.TlsConnection], 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 (iface,
      56  				       g_param_spec_enum ("authentication-mode", NULL, NULL,
      57  							  G_TYPE_TLS_AUTHENTICATION_MODE,
      58  							  G_TLS_AUTHENTICATION_NONE,
      59  							  G_PARAM_READWRITE |
      60  							  G_PARAM_STATIC_STRINGS));
      61  }
      62  
      63  /**
      64   * g_tls_server_connection_new:
      65   * @base_io_stream: the #GIOStream to wrap
      66   * @certificate: (nullable): the default server certificate, or %NULL
      67   * @error: #GError for error reporting, or %NULL to ignore.
      68   *
      69   * Creates a new #GTlsServerConnection wrapping @base_io_stream (which
      70   * must have pollable input and output streams).
      71   *
      72   * See the documentation for #GTlsConnection:base-io-stream for restrictions
      73   * on when application code can run operations on the @base_io_stream after
      74   * this function has returned.
      75   *
      76   * Returns: (transfer full) (type GTlsServerConnection): the new
      77   * #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  }