diff options
| author | Carlos Garcia Campos <cgarcia@igalia.com> | 2020-10-27 12:38:13 +0100 |
|---|---|---|
| committer | Carlos Garcia Campos <cgarcia@igalia.com> | 2020-10-27 12:41:32 +0100 |
| commit | bf95e5100ff3f59f846d65c18c33ee29d06a5c7c (patch) | |
| tree | 4eaa267f5650b16c2c5e04ac16c8b14d113f7882 | |
| parent | cb5a05d635a6fa6336eaf5e944b6b6ef7c8b3e11 (diff) | |
| download | libsoup-bf95e5100ff3f59f846d65c18c33ee29d06a5c7c.tar.gz | |
auth: Add port property to SoupAuth
The host name is not enough to identify the domain being authenticated,
we need the port too.
| -rw-r--r-- | docs/reference/libsoup-3.0-sections.txt | 1 | ||||
| -rw-r--r-- | libsoup/auth/soup-auth.c | 40 | ||||
| -rw-r--r-- | libsoup/auth/soup-auth.h | 3 | ||||
| -rw-r--r-- | tests/proxy-test.c | 18 |
4 files changed, 62 insertions, 0 deletions
diff --git a/docs/reference/libsoup-3.0-sections.txt b/docs/reference/libsoup-3.0-sections.txt index 9233c069..8d9b98e7 100644 --- a/docs/reference/libsoup-3.0-sections.txt +++ b/docs/reference/libsoup-3.0-sections.txt @@ -512,6 +512,7 @@ soup_auth_negotiate_supported soup_auth_is_for_proxy soup_auth_get_scheme_name soup_auth_get_host +soup_auth_get_port soup_auth_get_realm soup_auth_get_info <SUBSECTION> diff --git a/libsoup/auth/soup-auth.c b/libsoup/auth/soup-auth.c index 5fabd0a7..1486644d 100644 --- a/libsoup/auth/soup-auth.c +++ b/libsoup/auth/soup-auth.c @@ -38,6 +38,7 @@ typedef struct { char *realm; char *host; + guint port; gboolean proxy; gboolean cancelled; } SoupAuthPrivate; @@ -50,6 +51,7 @@ enum { PROP_SCHEME_NAME, PROP_REALM, PROP_HOST, + PROP_PORT, PROP_IS_FOR_PROXY, PROP_IS_AUTHENTICATED, PROP_IS_CANCELLED, @@ -102,6 +104,9 @@ soup_auth_set_property (GObject *object, guint prop_id, g_free (priv->host); priv->host = g_value_dup_string (value); break; + case PROP_PORT: + priv->port = g_value_get_uint (value); + break; case PROP_IS_FOR_PROXY: priv->proxy = g_value_get_boolean (value); break; @@ -128,6 +133,9 @@ soup_auth_get_property (GObject *object, guint prop_id, case PROP_HOST: g_value_set_string (value, soup_auth_get_host (auth)); break; + case PROP_PORT: + g_value_set_uint (value, soup_auth_get_port (auth)); + break; case PROP_IS_FOR_PROXY: g_value_set_boolean (value, priv->proxy); break; @@ -204,6 +212,19 @@ soup_auth_class_init (SoupAuthClass *auth_class) G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); /** + * SOUP_AUTH_PORT: + * + * An alias for the #SoupAuth:port property. (The + * port of the host being authenticated to.) + **/ + g_object_class_install_property ( + object_class, PROP_PORT, + g_param_spec_uint (SOUP_AUTH_PORT, + "Port", + "Authentication port", + 0, G_MAXUINT, 0, + G_PARAM_READWRITE)); + /** * SOUP_AUTH_IS_FOR_PROXY: * * An alias for the #SoupAuth:is-for-proxy property. (Whether @@ -281,6 +302,7 @@ soup_auth_new (GType type, SoupMessage *msg, const char *auth_header) auth = g_object_new (type, SOUP_AUTH_IS_FOR_PROXY, (msg->status_code == SOUP_STATUS_PROXY_UNAUTHORIZED), SOUP_AUTH_HOST, uri->host, + SOUP_AUTH_PORT, uri->port, NULL); SoupAuthPrivate *priv = soup_auth_get_instance_private (auth); @@ -463,6 +485,24 @@ soup_auth_get_host (SoupAuth *auth) } /** + * soup_auth_get_port: + * @auth: a #SoupAuth + * + * Returns the port that @auth is associated with. + * + * Return value: the port + **/ +guint +soup_auth_get_port (SoupAuth *auth) +{ + SoupAuthPrivate *priv = soup_auth_get_instance_private (auth); + + g_return_val_if_fail (SOUP_IS_AUTH (auth), 0); + + return priv->port; +} + +/** * soup_auth_get_realm: * @auth: a #SoupAuth * diff --git a/libsoup/auth/soup-auth.h b/libsoup/auth/soup-auth.h index c3375a7a..ca3041a7 100644 --- a/libsoup/auth/soup-auth.h +++ b/libsoup/auth/soup-auth.h @@ -46,6 +46,7 @@ struct _SoupAuthClass { #define SOUP_AUTH_SCHEME_NAME "scheme-name" #define SOUP_AUTH_REALM "realm" #define SOUP_AUTH_HOST "host" +#define SOUP_AUTH_PORT "port" #define SOUP_AUTH_IS_FOR_PROXY "is-for-proxy" #define SOUP_AUTH_IS_AUTHENTICATED "is-authenticated" #define SOUP_AUTH_IS_CANCELLED "is-cancelled" @@ -65,6 +66,8 @@ SOUP_AVAILABLE_IN_2_4 const char *soup_auth_get_scheme_name (SoupAuth *auth); SOUP_AVAILABLE_IN_2_4 const char *soup_auth_get_host (SoupAuth *auth); +SOUP_AVAILABLE_IN_ALL +guint soup_auth_get_port (SoupAuth *auth); SOUP_AVAILABLE_IN_2_4 const char *soup_auth_get_realm (SoupAuth *auth); SOUP_AVAILABLE_IN_2_4 diff --git a/tests/proxy-test.c b/tests/proxy-test.c index bc6fb2b8..1595c8f7 100644 --- a/tests/proxy-test.c +++ b/tests/proxy-test.c @@ -46,6 +46,24 @@ authenticate (SoupMessage *msg, SoupAuth *auth, gboolean retrying) { + if (soup_auth_is_for_proxy (auth)) { + char *uri; + int i; + gboolean found = FALSE; + + uri = g_strdup_printf ("http://%s:%u", soup_auth_get_host (auth), soup_auth_get_port (auth)); + for (i = 1; i < G_N_ELEMENTS (proxies) && !found; i++) { + if (strcmp (uri, proxies[i]) == 0) + found = TRUE; + } + g_assert_true (found); + } else { + SoupURI *uri = soup_message_get_uri (msg); + + g_assert_cmpstr (uri->host, ==, soup_auth_get_host (auth)); + g_assert_cmpuint (uri->port, ==, soup_auth_get_port (auth)); + } + if (!retrying) { soup_auth_authenticate (auth, "user1", "realm1"); |
