Blame gio/gdtlsserverconnection.c

Packit ae235b
/* GIO - GLib Input, Output and Streaming Library
Packit ae235b
 *
Packit ae235b
 * Copyright © 2010 Red Hat, Inc
Packit ae235b
 * Copyright © 2015 Collabora, Ltd.
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 "gdtlsserverconnection.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:gdtlsserverconnection
Packit ae235b
 * @short_description: DTLS server-side connection
Packit ae235b
 * @include: gio/gio.h
Packit ae235b
 *
Packit ae235b
 * #GDtlsServerConnection is the server-side subclass of #GDtlsConnection,
Packit ae235b
 * representing a server-side DTLS connection.
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
Packit ae235b
G_DEFINE_INTERFACE (GDtlsServerConnection, g_dtls_server_connection,
Packit ae235b
                    G_TYPE_DTLS_CONNECTION)
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_dtls_server_connection_default_init (GDtlsServerConnectionInterface *iface)
Packit ae235b
{
Packit ae235b
  /**
Packit ae235b
   * GDtlsServerConnection:authentication-mode:
Packit ae235b
   *
Packit ae235b
   * The #GTlsAuthenticationMode for the server. This can be changed
Packit ae235b
   * before calling g_dtls_connection_handshake() if you want to
Packit ae235b
   * rehandshake with a different mode from the initial handshake.
Packit ae235b
   *
Packit ae235b
   * Since: 2.48
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_dtls_server_connection_new:
Packit ae235b
 * @base_socket: the #GDatagramBased 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 #GDtlsServerConnection wrapping @base_socket.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full) (type GDtlsServerConnection): the new
Packit ae235b
 *   #GDtlsServerConnection, or %NULL on error
Packit ae235b
 *
Packit ae235b
 * Since: 2.48
Packit ae235b
 */
Packit ae235b
GDatagramBased *
Packit ae235b
g_dtls_server_connection_new (GDatagramBased   *base_socket,
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_dtls_server_connection_type (backend),
Packit ae235b
                         NULL, error,
Packit ae235b
                         "base-socket", base_socket,
Packit ae235b
                         "certificate", certificate,
Packit ae235b
                         NULL);
Packit ae235b
  return G_DATAGRAM_BASED (conn);
Packit ae235b
}