[libsoup/carlosgc/server-client-side-certs: 1/2] server: remove soup_server_set_ssl_cert_file()
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/carlosgc/server-client-side-certs: 1/2] server: remove soup_server_set_ssl_cert_file()
- Date: Tue, 15 Jun 2021 14:16:12 +0000 (UTC)
commit 4fa797dca7346fd5c3f9bb9c3b9fa6a39fd28d43
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Tue Jun 15 11:15:44 2021 +0200
server: remove soup_server_set_ssl_cert_file()
It's changing a construct-only property by providing API to create a
GTlsCertificate. This patch makes SoupServer:tls-certificate a readable
and writable property and adds a public getter and setter.
docs/reference/libsoup-3.0-sections.txt | 3 +-
libsoup/server/soup-server.c | 74 ++++++++++++++++-----------------
libsoup/server/soup-server.h | 9 ++--
3 files changed, 43 insertions(+), 43 deletions(-)
---
diff --git a/docs/reference/libsoup-3.0-sections.txt b/docs/reference/libsoup-3.0-sections.txt
index 9e339e07..5d695e69 100644
--- a/docs/reference/libsoup-3.0-sections.txt
+++ b/docs/reference/libsoup-3.0-sections.txt
@@ -225,7 +225,8 @@ soup_status_get_phrase
<TITLE>SoupServer</TITLE>
SoupServer
soup_server_new
-soup_server_set_ssl_cert_file
+soup_server_set_tls_certificate
+soup_server_get_tls_certificate
<SUBSECTION>
SoupServerListenOptions
soup_server_listen
diff --git a/libsoup/server/soup-server.c b/libsoup/server/soup-server.c
index 65afc2c6..d2cce7c3 100644
--- a/libsoup/server/soup-server.c
+++ b/libsoup/server/soup-server.c
@@ -101,11 +101,10 @@
* If you want to handle the special "*" URI (eg, "OPTIONS *"), you
* must explicitly register a handler for "*"; the default handler
* will not be used for that case.
- *
+ *
* If you want to process https connections in addition to (or instead
- * of) http connections, you can either set the
- * SoupServer:tls-certificate property when creating the server, or
- * else call soup_server_set_ssl_cert_file() after creating it.
+ * of) http connections, you can set the #SoupServer:tls-certificate
+ * property.
*
* Once the server is set up, make one or more calls to
* soup_server_listen(), soup_server_listen_local(), or
@@ -268,9 +267,7 @@ soup_server_set_property (GObject *object, guint prop_id,
switch (prop_id) {
case PROP_TLS_CERTIFICATE:
- if (priv->tls_cert)
- g_object_unref (priv->tls_cert);
- priv->tls_cert = g_value_dup_object (value);
+ soup_server_set_tls_certificate (server, g_value_get_object (value));
break;
case PROP_RAW_PATHS:
priv->raw_paths = g_value_get_boolean (value);
@@ -434,10 +431,6 @@ soup_server_class_init (SoupServerClass *server_class)
* A #GTlsCertificate that has a #GTlsCertificate:private-key
* set. If this is set, then the server will be able to speak
* https in addition to (or instead of) plain http.
- *
- * Alternatively, you can call soup_server_set_ssl_cert_file()
- * to have #SoupServer read in a a certificate from a file.
- *
*/
properties[PROP_TLS_CERTIFICATE] =
g_param_spec_object ("tls-certificate",
@@ -445,7 +438,7 @@ soup_server_class_init (SoupServerClass *server_class)
"GTlsCertificate to use for https",
G_TYPE_TLS_CERTIFICATE,
G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS);
properties[PROP_RAW_PATHS] =
@@ -524,41 +517,46 @@ soup_server_new (const char *optname1, ...)
}
/**
- * soup_server_set_ssl_cert_file:
+ * soup_server_set_tls_certificate:
* @server: a #SoupServer
- * @ssl_cert_file: path to a file containing a PEM-encoded SSL/TLS
- * certificate.
- * @ssl_key_file: path to a file containing a PEM-encoded private key.
- * @error: return location for a #GError
- *
- * Sets @server up to do https, using the SSL/TLS certificate
- * specified by @ssl_cert_file and @ssl_key_file (which may point to
- * the same file).
- *
- * Alternatively, you can set the #SoupServer:tls-certificate property
- * at construction time, if you already have a #GTlsCertificate.
- *
- * Returns: success or failure.
+ * @certificate: a #GTlsCertificate
*
+ * Sets @server up to do https, using the given SSL/TLS @certificate.
*/
-gboolean
-soup_server_set_ssl_cert_file (SoupServer *server,
- const char *ssl_cert_file,
- const char *ssl_key_file,
- GError **error)
+void
+soup_server_set_tls_certificate (SoupServer *server,
+ GTlsCertificate *certificate)
{
SoupServerPrivate *priv;
- g_return_val_if_fail (SOUP_IS_SERVER (server), FALSE);
+ g_return_if_fail (SOUP_IS_SERVER (server));
+
priv = soup_server_get_instance_private (server);
+ if (priv->tls_cert == certificate)
+ return;
- if (priv->tls_cert)
- g_object_unref (priv->tls_cert);
+ g_clear_object (&priv->tls_cert);
+ priv->tls_cert = certificate ? g_object_ref (certificate) : NULL;
+ g_object_notify_by_pspec (G_OBJECT (server), properties[PROP_TLS_CERTIFICATE]);
+}
- priv->tls_cert = g_tls_certificate_new_from_files (ssl_cert_file,
- ssl_key_file,
- error);
- return priv->tls_cert != NULL;
+/**
+ * soup_server_get_tls_certificate:
+ * @server: a #SoupServer
+ *
+ * Gets the @server SSL/TLS certificate
+ *
+ * Returns: (transfer none) (nullable): a #GTlsCertificate or %NULL
+ */
+GTlsCertificate *
+soup_server_get_tls_certificate (SoupServer *server)
+{
+ SoupServerPrivate *priv;
+
+ g_return_val_if_fail (SOUP_IS_SERVER (server), NULL);
+
+ priv = soup_server_get_instance_private (server);
+ return priv->tls_cert;
}
/**
diff --git a/libsoup/server/soup-server.h b/libsoup/server/soup-server.h
index 3f7d911e..8f9a977a 100644
--- a/libsoup/server/soup-server.h
+++ b/libsoup/server/soup-server.h
@@ -42,10 +42,11 @@ SoupServer *soup_server_new (const char *optnam
...) G_GNUC_NULL_TERMINATED;
SOUP_AVAILABLE_IN_ALL
-gboolean soup_server_set_ssl_cert_file (SoupServer *server,
- const char *ssl_cert_file,
- const char *ssl_key_file,
- GError **error);
+void soup_server_set_tls_certificate (SoupServer *server,
+ GTlsCertificate *certificate);
+SOUP_AVAILABLE_IN_ALL
+GTlsCertificate *soup_server_get_tls_certificate (SoupServer *server);
+
SOUP_AVAILABLE_IN_ALL
gboolean soup_server_is_https (SoupServer *server);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]