Blame gio/gtlsserverconnection.c

Packit ae235b
/* GIO - GLib Input, Output and Streaming Library
Packit ae235b
 *
Packit ae235b
 * Copyright © 2010 Red Hat, Inc
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
#include "glib.h"
Packit ae235b
Packit ae235b
#include "gtlsserverconnection.h"
Packit ae235b
#include "ginitable.h"
Packit ae235b
#include "gioenumtypes.h"
Packit ae235b
#include "gsocket.h"
Packit ae235b
#include "gtlsbackend.h"
Packit ae235b
#include "gtlscertificate.h"
Packit ae235b
#include "glibintl.h"
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:gtlsserverconnection
Packit ae235b
 * @short_description: TLS server-side connection
Packit ae235b
 * @include: gio/gio.h
Packit ae235b
 *
Packit ae235b
 * #GTlsServerConnection is the server-side subclass of #GTlsConnection,
Packit ae235b
 * representing a server-side TLS connection.
Packit ae235b
 *
Packit ae235b
 * Since: 2.28
Packit ae235b
 */
Packit ae235b
Packit ae235b
G_DEFINE_INTERFACE (GTlsServerConnection, g_tls_server_connection, G_TYPE_TLS_CONNECTION)
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_tls_server_connection_default_init (GTlsServerConnectionInterface *iface)
Packit ae235b
{
Packit ae235b
  /**
Packit ae235b
   * GTlsServerConnection:authentication-mode:
Packit ae235b
   *
Packit ae235b
   * The #GTlsAuthenticationMode for the server. This can be changed
Packit ae235b
   * before calling g_tls_connection_handshake() if you want to
Packit ae235b
   * rehandshake with a different mode from the initial handshake.
Packit ae235b
   *
Packit ae235b
   * Since: 2.28
Packit ae235b
   */
Packit ae235b
  g_object_interface_install_property (iface,
Packit ae235b
				       g_param_spec_enum ("authentication-mode",
Packit ae235b
							  P_("Authentication Mode"),
Packit ae235b
							  P_("The client authentication mode"),
Packit ae235b
							  G_TYPE_TLS_AUTHENTICATION_MODE,
Packit ae235b
							  G_TLS_AUTHENTICATION_NONE,
Packit ae235b
							  G_PARAM_READWRITE |
Packit ae235b
							  G_PARAM_STATIC_STRINGS));
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_tls_server_connection_new:
Packit ae235b
 * @base_io_stream: the #GIOStream to wrap
Packit ae235b
 * @certificate: (nullable): the default server certificate, or %NULL
Packit ae235b
 * @error: #GError for error reporting, or %NULL to ignore.
Packit ae235b
 *
Packit ae235b
 * Creates a new #GTlsServerConnection wrapping @base_io_stream (which
Packit ae235b
 * must have pollable input and output streams).
Packit ae235b
 *
Packit ae235b
 * See the documentation for #GTlsConnection:base-io-stream for restrictions
Packit ae235b
 * on when application code can run operations on the @base_io_stream after
Packit ae235b
 * this function has returned.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full) (type GTlsServerConnection): the new
Packit ae235b
 * #GTlsServerConnection, or %NULL on error
Packit ae235b
 *
Packit ae235b
 * Since: 2.28
Packit ae235b
 */
Packit ae235b
GIOStream *
Packit ae235b
g_tls_server_connection_new (GIOStream        *base_io_stream,
Packit ae235b
			     GTlsCertificate  *certificate,
Packit ae235b
			     GError          **error)
Packit ae235b
{
Packit ae235b
  GObject *conn;
Packit ae235b
  GTlsBackend *backend;
Packit ae235b
Packit ae235b
  backend = g_tls_backend_get_default ();
Packit ae235b
  conn = g_initable_new (g_tls_backend_get_server_connection_type (backend),
Packit ae235b
			 NULL, error,
Packit ae235b
			 "base-io-stream", base_io_stream,
Packit ae235b
			 "certificate", certificate,
Packit ae235b
			 NULL);
Packit ae235b
  return G_IO_STREAM (conn);
Packit ae235b
}