summaryrefslogtreecommitdiff
path: root/libsoup
diff options
context:
space:
mode:
Diffstat (limited to 'libsoup')
-rw-r--r--libsoup/auth/soup-auth-manager.c2
-rw-r--r--libsoup/hsts/soup-hsts-enforcer.c19
-rw-r--r--libsoup/server/soup-server.c23
-rw-r--r--libsoup/soup-message.c21
-rw-r--r--libsoup/soup-session.c30
-rw-r--r--libsoup/soup-uri-utils-private.h4
-rw-r--r--libsoup/soup-uri-utils.c163
-rw-r--r--libsoup/soup-uri-utils.h25
8 files changed, 110 insertions, 177 deletions
diff --git a/libsoup/auth/soup-auth-manager.c b/libsoup/auth/soup-auth-manager.c
index 3a52aa7c..26be2ead 100644
--- a/libsoup/auth/soup-auth-manager.c
+++ b/libsoup/auth/soup-auth-manager.c
@@ -554,7 +554,7 @@ authenticate_auth (SoupAuthManager *manager, SoupAuth *auth,
*/
if (g_uri_get_password (uri) && g_uri_get_user (uri)) {
soup_auth_authenticate (auth, g_uri_get_user (uri), g_uri_get_password (uri));
- GUri *new_uri = soup_uri_copy_with_credentials (uri, NULL, NULL);
+ GUri *new_uri = soup_uri_copy (uri, SOUP_URI_USER, NULL, SOUP_URI_PASSWORD, NULL, SOUP_URI_NONE);
soup_message_set_uri (msg, new_uri); // QUESTION: This didn't emit a signal previously
g_uri_unref (new_uri);
} else if (!soup_auth_is_authenticated (auth) && can_interact) {
diff --git a/libsoup/hsts/soup-hsts-enforcer.c b/libsoup/hsts/soup-hsts-enforcer.c
index 05155e0d..5a297bca 100644
--- a/libsoup/hsts/soup-hsts-enforcer.c
+++ b/libsoup/hsts/soup-hsts-enforcer.c
@@ -488,23 +488,6 @@ got_sts_header_cb (SoupMessage *msg, gpointer user_data)
soup_hsts_enforcer_process_sts_header (hsts_enforcer, msg);
}
-static GUri *
-copy_uri_with_new_scheme (GUri *uri, const char *scheme, int port)
-{
- return g_uri_build_with_user (
- g_uri_get_flags (uri),
- scheme,
- g_uri_get_user (uri),
- g_uri_get_password (uri),
- g_uri_get_auth_params (uri),
- g_uri_get_host (uri),
- port,
- g_uri_get_path (uri),
- g_uri_get_query (uri),
- g_uri_get_fragment (uri)
- );
-}
-
static void
rewrite_message_uri_to_https (SoupMessage *msg)
{
@@ -518,7 +501,7 @@ rewrite_message_uri_to_https (SoupMessage *msg)
if (port == 80)
port = 443;
- new_uri = copy_uri_with_new_scheme (uri, "https", port);
+ new_uri = soup_uri_copy (uri, SOUP_URI_SCHEME, "https", SOUP_URI_PORT, port, SOUP_URI_NONE);
soup_message_set_uri (msg, new_uri);
g_uri_unref (new_uri);
}
diff --git a/libsoup/server/soup-server.c b/libsoup/server/soup-server.c
index 58bbd9c9..0fe41740 100644
--- a/libsoup/server/soup-server.c
+++ b/libsoup/server/soup-server.c
@@ -777,23 +777,6 @@ call_handler (SoupServer *server,
g_hash_table_unref (form_data_set);
}
-static GUri *
-uri_set_path (GUri *uri, const char *path)
-{
- return g_uri_build_with_user (
- g_uri_get_flags (uri) ^ G_URI_FLAGS_ENCODED_PATH,
- g_uri_get_scheme (uri),
- g_uri_get_user (uri),
- g_uri_get_password (uri),
- g_uri_get_auth_params (uri),
- g_uri_get_host (uri),
- g_uri_get_port (uri),
- path,
- g_uri_get_query (uri),
- g_uri_get_fragment (uri)
- );
-}
-
static void
got_headers (SoupServer *server,
SoupServerMessage *msg)
@@ -832,6 +815,7 @@ got_headers (SoupServer *server,
if (!priv->raw_paths && g_uri_get_flags (uri) & G_URI_FLAGS_ENCODED_PATH) {
char *decoded_path;
+ GUri *copy;
decoded_path = g_uri_unescape_string (g_uri_get_path (uri), NULL);
@@ -851,9 +835,10 @@ got_headers (SoupServer *server,
return;
}
- uri = uri_set_path (uri, decoded_path);
- soup_server_message_set_uri (msg, uri);
+ copy = soup_uri_copy (uri, SOUP_URI_PATH, decoded_path, SOUP_URI_NONE);
+ soup_server_message_set_uri (msg, copy);
g_free (decoded_path);
+ g_uri_unref (copy);
}
/* Now handle authentication. (We do this here so that if
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index ee1e2ea7..a302f236 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -812,23 +812,6 @@ soup_message_new_from_uri (const char *method, GUri *uri)
NULL);
}
-static GUri *
-copy_uri_with_new_query (GUri *uri, const char *query)
-{
- return g_uri_build_with_user (
- g_uri_get_flags (uri),
- g_uri_get_scheme (uri),
- g_uri_get_user (uri),
- g_uri_get_password (uri),
- g_uri_get_auth_params (uri),
- g_uri_get_host (uri),
- g_uri_get_port (uri),
- g_uri_get_path (uri),
- query,
- g_uri_get_fragment (uri)
- );
-}
-
/**
* soup_message_new_from_encoded_form:
* @method: the HTTP method for the created request (GET, POST or PUT)
@@ -866,7 +849,7 @@ soup_message_new_from_encoded_form (const char *method,
}
if (strcmp (method, "GET") == 0) {
- GUri *new_uri = copy_uri_with_new_query (uri, encoded_form);
+ GUri *new_uri = soup_uri_copy (uri, SOUP_URI_QUERY, encoded_form, SOUP_URI_NONE);
msg = soup_message_new_from_uri (method, new_uri);
g_uri_unref (new_uri);
} else if (strcmp (method, "POST") == 0 || strcmp (method, "PUT") == 0) {
@@ -2195,4 +2178,4 @@ soup_message_is_options_ping (SoupMessage *msg)
SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
return priv->options_ping;
-} \ No newline at end of file
+}
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 4ba0b7b3..608b7411 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -670,24 +670,6 @@ soup_host_uri_equal (gconstpointer v1, gconstpointer v2)
return g_ascii_strcasecmp (one_host, two_host) == 0;
}
-static GUri *
-copy_uri_with_new_scheme (GUri *uri, const char *scheme)
-{
- return g_uri_build_with_user (
- g_uri_get_flags (uri),
- scheme,
- g_uri_get_user (uri),
- g_uri_get_password (uri),
- g_uri_get_auth_params (uri),
- g_uri_get_host (uri),
- g_uri_get_port (uri),
- g_uri_get_path (uri),
- g_uri_get_query (uri),
- g_uri_get_fragment (uri)
- );
-}
-
-
static SoupSessionHost *
soup_session_host_new (SoupSession *session, GUri *uri)
{
@@ -699,10 +681,10 @@ soup_session_host_new (SoupSession *session, GUri *uri)
g_strcmp0 (scheme, "https")) {
SoupSessionPrivate *priv = soup_session_get_instance_private (session);
- if (soup_uri_is_https (uri, priv->https_aliases))
- host->uri = copy_uri_with_new_scheme (uri, "https");
- else
- host->uri = copy_uri_with_new_scheme (uri, "http");
+ host->uri = soup_uri_copy (uri,
+ SOUP_URI_SCHEME, soup_uri_is_https (uri, priv->https_aliases) ?
+ "https" : "http",
+ SOUP_URI_NONE);
} else
host->uri = g_uri_ref (uri);
@@ -735,7 +717,9 @@ get_host_for_uri (SoupSession *session, GUri *uri)
return host;
if (!soup_uri_is_http (uri, NULL) && !soup_uri_is_https (uri, NULL)) {
- uri = uri_tmp = copy_uri_with_new_scheme (uri, https ? "https" : "http");
+ uri = uri_tmp = soup_uri_copy (uri,
+ SOUP_URI_SCHEME, https ? "https" : "http",
+ SOUP_URI_NONE);
}
host = soup_session_host_new (session, uri);
if (uri_tmp)
diff --git a/libsoup/soup-uri-utils-private.h b/libsoup/soup-uri-utils-private.h
index ed137f90..b741a6d7 100644
--- a/libsoup/soup-uri-utils-private.h
+++ b/libsoup/soup-uri-utils-private.h
@@ -18,10 +18,6 @@ gboolean soup_uri_is_https (GUri *uri,
gboolean soup_uri_uses_default_port (GUri *uri);
-GUri *soup_uri_copy_with_credentials (GUri *uri,
- const char *username,
- const char *password);
-
char *soup_uri_get_path_and_query (GUri *uri);
GUri *soup_uri_copy_host (GUri *uri);
diff --git a/libsoup/soup-uri-utils.c b/libsoup/soup-uri-utils.c
index de843ae1..f2e4e76d 100644
--- a/libsoup/soup-uri-utils.c
+++ b/libsoup/soup-uri-utils.c
@@ -179,86 +179,19 @@ soup_uri_uses_default_port (GUri *uri)
return FALSE;
}
-static GUri *
-soup_uri_copy_with_query (GUri *uri, const char *query)
-{
- return g_uri_build_with_user (
- g_uri_get_flags (uri) | G_URI_FLAGS_ENCODED_QUERY,
- g_uri_get_scheme (uri),
- g_uri_get_user (uri),
- g_uri_get_password (uri),
- g_uri_get_auth_params (uri),
- g_uri_get_host (uri),
- g_uri_get_port (uri),
- g_uri_get_path (uri),
- query,
- g_uri_get_fragment (uri)
- );
-}
-
-/**
- * soup_uri_copy_with_query_from_form:
- * @uri: a #GUri
- * @form: (element-type utf8 utf8): a #GHashTable containing HTML form
- * information
- *
- * Sets @uri's query to the result of encoding @form according to the
- * HTML form rules. See soup_form_encode_hash() for more information.
- *
- * Returns: (transfer full): A new #GUri
- **/
-GUri *
-soup_uri_copy_with_query_from_form (GUri *uri, GHashTable *form)
-{
- g_return_val_if_fail (uri != NULL, NULL);
-
- char *query = soup_form_encode_hash (form);
- GUri *new_uri = soup_uri_copy_with_query (uri, query);
- g_free (query);
- return new_uri;
-}
-
-/**
- * soup_uri_copy_with_query_from_fields:
- * @uri: a #GUri
- * @first_field: name of the first form field to encode into query
- * @...: value of @first_field, followed by additional field names
- * and values, terminated by %NULL.
- *
- * Sets @uri's query to the result of encoding the given form fields
- * and values according to the * HTML form rules. See
- * soup_form_encode() for more information.
- *
- * Returns: (transfer full): A new #GUri
- **/
-GUri *
-soup_uri_copy_with_query_from_fields (GUri *uri,
- const char *first_field,
- ...)
-{
- va_list args;
-
- g_return_val_if_fail (uri != NULL, NULL);
-
- va_start (args, first_field);
- char *query = soup_form_encode_valist (first_field, args);
- va_end (args);
-
- GUri *new_uri = soup_uri_copy_with_query (uri, query);
- g_free (query);
- return new_uri;
-}
-
GUri *
soup_uri_copy_host (GUri *uri)
{
g_return_val_if_fail (uri != NULL, NULL);
- return g_uri_build (g_uri_get_flags (uri),
- g_uri_get_scheme (uri), NULL,
- g_uri_get_host (uri),
- g_uri_get_port (uri),
- "/", NULL, NULL);
+ return soup_uri_copy (uri,
+ SOUP_URI_USER, NULL,
+ SOUP_URI_PASSWORD, NULL,
+ SOUP_URI_AUTH_PARAMS, NULL,
+ SOUP_URI_PATH, "/",
+ SOUP_URI_QUERY, NULL,
+ SOUP_URI_FRAGMENT, NULL,
+ SOUP_URI_NONE);
}
/**
@@ -453,21 +386,81 @@ soup_uri_decode_data_uri (const char *uri,
return bytes;
}
+/**
+ * SoupURIComponent:
+ * @SOUP_URI_NONE: no component
+ * @SOUP_URI_SCHEME: the URI scheme component
+ * @SOUP_URI_USER: the URI user component
+ * @SOUP_URI_PASSWORD: the URI password component
+ * @SOUP_URI_AUTH_PARAMS: the URI authentication parameters component
+ * @SOUP_URI_HOST: the URI host component
+ * @SOUP_URI_PORT: the URI port component
+ * @SOUP_URI_PATH: the URI path component
+ * @SOUP_URI_QUERY: the URI query component
+ * @SOUP_URI_FRAGMENT: the URI fragment component
+ *
+ * Enum values passed to soup_uri_copy() to indicate the components of
+ * the URI that should be updated with the given values.
+ */
+
+/**
+ * soup_uri_copy: (skip)
+ * @uri: the #GUri to copy
+ * @first_component: first #SoupURIComponent to update
+ * @...: value of @first_component followed by additional
+ * components and values, terminated by %SOUP_URI_NONE
+ *
+ * Return a copy of @uri with the given components updated
+ *
+ * Returns: (transfer full): a new #GUri
+ */
GUri *
-soup_uri_copy_with_credentials (GUri *uri, const char *username, const char *password)
+soup_uri_copy (GUri *uri,
+ SoupURIComponent first_component,
+ ...)
{
+ va_list args;
+ SoupURIComponent component = first_component;
+ gpointer values[SOUP_URI_FRAGMENT + 1];
+ gboolean values_to_set[SOUP_URI_FRAGMENT + 1];
+ GUriFlags flags = g_uri_get_flags (uri);
+
g_return_val_if_fail (uri != NULL, NULL);
+ memset (&values_to_set, 0, sizeof (values_to_set));
+
+ va_start (args, first_component);
+ while (component != SOUP_URI_NONE) {
+ if (component == SOUP_URI_PORT)
+ values[component] = GINT_TO_POINTER (va_arg (args, glong));
+ else
+ values[component] = va_arg (args, gpointer);
+ values_to_set[component] = TRUE;
+ component = va_arg (args, SoupURIComponent);
+ }
+ va_end (args);
+
+ if (values_to_set[SOUP_URI_PASSWORD])
+ flags |= G_URI_FLAGS_HAS_PASSWORD;
+ if (values_to_set[SOUP_URI_AUTH_PARAMS])
+ flags |= G_URI_FLAGS_HAS_AUTH_PARAMS;
+ if (values_to_set[SOUP_URI_PATH])
+ flags |= G_URI_FLAGS_ENCODED_PATH;
+ if (values_to_set[SOUP_URI_QUERY])
+ flags |= G_URI_FLAGS_ENCODED_QUERY;
+ if (values_to_set[SOUP_URI_FRAGMENT])
+ flags |= G_URI_FLAGS_ENCODED_FRAGMENT;
return g_uri_build_with_user (
- g_uri_get_flags (uri) | G_URI_FLAGS_HAS_PASSWORD,
- g_uri_get_scheme (uri),
- username, password,
- g_uri_get_auth_params (uri),
- g_uri_get_host (uri),
- g_uri_get_port (uri),
- g_uri_get_path (uri),
- g_uri_get_query (uri),
- g_uri_get_fragment (uri)
+ flags,
+ values_to_set[SOUP_URI_SCHEME] ? values[SOUP_URI_SCHEME] : g_uri_get_scheme (uri),
+ values_to_set[SOUP_URI_USER] ? values[SOUP_URI_USER] : g_uri_get_user (uri),
+ values_to_set[SOUP_URI_PASSWORD] ? values[SOUP_URI_PASSWORD] : g_uri_get_password (uri),
+ values_to_set[SOUP_URI_AUTH_PARAMS] ? values[SOUP_URI_AUTH_PARAMS] : g_uri_get_auth_params (uri),
+ values_to_set[SOUP_URI_HOST] ? values[SOUP_URI_HOST] : g_uri_get_host (uri),
+ values_to_set[SOUP_URI_PORT] ? GPOINTER_TO_INT (values[SOUP_URI_PORT]) : g_uri_get_port (uri),
+ values_to_set[SOUP_URI_PATH] ? values[SOUP_URI_PATH] : g_uri_get_path (uri),
+ values_to_set[SOUP_URI_QUERY] ? values[SOUP_URI_QUERY] : g_uri_get_query (uri),
+ values_to_set[SOUP_URI_FRAGMENT] ? values[SOUP_URI_FRAGMENT] : g_uri_get_fragment (uri)
);
}
diff --git a/libsoup/soup-uri-utils.h b/libsoup/soup-uri-utils.h
index 8b436180..e4072b4c 100644
--- a/libsoup/soup-uri-utils.h
+++ b/libsoup/soup-uri-utils.h
@@ -11,6 +11,19 @@
G_BEGIN_DECLS
+typedef enum {
+ SOUP_URI_NONE,
+ SOUP_URI_SCHEME,
+ SOUP_URI_USER,
+ SOUP_URI_PASSWORD,
+ SOUP_URI_AUTH_PARAMS,
+ SOUP_URI_HOST,
+ SOUP_URI_PORT,
+ SOUP_URI_PATH,
+ SOUP_URI_QUERY,
+ SOUP_URI_FRAGMENT
+} SoupURIComponent;
+
SOUP_AVAILABLE_IN_ALL
GBytes *soup_uri_decode_data_uri (const char *uri,
char **content_type);
@@ -19,17 +32,13 @@ SOUP_AVAILABLE_IN_ALL
gboolean soup_uri_equal (GUri *uri1, GUri *uri2);
SOUP_AVAILABLE_IN_ALL
-GUri *soup_uri_copy_with_query_from_form (GUri *uri,
- GHashTable *form);
+int soup_uri_get_port_with_default (GUri *uri);
-SOUP_AVAILABLE_IN_ALL
-GUri *soup_uri_copy_with_query_from_fields (GUri *uri,
- const char *first_field,
- ...) G_GNUC_NULL_TERMINATED;
SOUP_AVAILABLE_IN_ALL
-int soup_uri_get_port_with_default (GUri *uri);
-
+GUri *soup_uri_copy (GUri *uri,
+ SoupURIComponent first_component,
+ ...);
#define SOUP_HTTP_URI_FLAGS (G_URI_FLAGS_HAS_PASSWORD | G_URI_FLAGS_ENCODED_PATH | G_URI_FLAGS_ENCODED_QUERY | G_URI_FLAGS_ENCODED_FRAGMENT | G_URI_FLAGS_SCHEME_NORMALIZE)
G_END_DECLS