From 737eef099ca1e34d18245c54b6ed3ba54faf1f9c Mon Sep 17 00:00:00 2001 From: Patrick Griffis Date: Mon, 27 Jul 2020 18:07:37 +0400 Subject: Replace SoupURI with GUri --- examples/get.c | 29 ++++++++++++++++------------- examples/simple-httpd.c | 6 +++--- examples/simple-proxy.c | 10 +++++----- 3 files changed, 24 insertions(+), 21 deletions(-) (limited to 'examples') diff --git a/examples/get.c b/examples/get.c index a03404d9..377cf854 100644 --- a/examples/get.c +++ b/examples/get.c @@ -39,7 +39,7 @@ get_url (const char *url) soup_session_queue_message (session, msg, finished, loop); g_main_loop_run (loop); - name = soup_message_get_uri (msg)->path; + name = g_uri_get_path (soup_message_get_uri (msg)); if (!debug) { if (soup_message_get_status (msg) == SOUP_STATUS_SSL_FAILED) { @@ -57,17 +57,18 @@ get_url (const char *url) header = soup_message_headers_get_one (soup_message_get_response_headers (msg), "Location"); if (header) { - SoupURI *uri; + GUri *uri; char *uri_string; if (!debug && !quiet) g_print (" -> %s\n", header); - uri = soup_uri_new_with_base (soup_message_get_uri (msg), header); - uri_string = soup_uri_to_string (uri, FALSE); + uri = g_uri_parse_relative (soup_message_get_uri (msg), header, SOUP_HTTP_URI_FLAGS, NULL); + g_assert (uri != NULL); + uri_string = g_uri_to_string (uri); get_url (uri_string); g_free (uri_string); - soup_uri_free (uri); + g_uri_unref (uri); } } else if (!head && SOUP_STATUS_IS_SUCCESSFUL (soup_message_get_status (msg))) { if (output_file_path) { @@ -190,7 +191,7 @@ main (int argc, char **argv) { GOptionContext *opts; const char *url; - SoupURI *proxy_uri, *parsed; + GUri *proxy_uri, *parsed; GError *error = NULL; SoupLogger *logger = NULL; char *help; @@ -216,12 +217,12 @@ main (int argc, char **argv) g_option_context_free (opts); url = argv[1]; - parsed = soup_uri_new (url); + parsed = g_uri_parse (url, SOUP_HTTP_URI_FLAGS, &error); if (!parsed) { - g_printerr ("Could not parse '%s' as a URL\n", url); + g_printerr ("Could not parse '%s' as a URL: %s\n", url, error->message); exit (1); } - soup_uri_free (parsed); + g_uri_unref (parsed); session = g_object_new (SOUP_TYPE_SESSION, "user-agent", "get ", @@ -258,10 +259,12 @@ main (int argc, char **argv) if (proxy) { GProxyResolver *resolver; - proxy_uri = soup_uri_new (proxy); + GError *error; + proxy_uri = g_uri_parse (proxy, SOUP_HTTP_URI_FLAGS, &error); if (!proxy_uri) { - g_printerr ("Could not parse '%s' as URI\n", - proxy); + g_printerr ("Could not parse '%s' as URI: %s\n", + proxy, error->message); + g_error_free (error); exit (1); } @@ -269,7 +272,7 @@ main (int argc, char **argv) g_object_set (G_OBJECT (session), "proxy-resolver", resolver, NULL); - soup_uri_free (proxy_uri); + g_uri_unref (proxy_uri); g_object_unref (resolver); } diff --git a/examples/simple-httpd.c b/examples/simple-httpd.c index 3c5b534b..f468ce18 100644 --- a/examples/simple-httpd.c +++ b/examples/simple-httpd.c @@ -93,7 +93,7 @@ do_get (SoupServer *server, SoupMessage *msg, const char *path) if (!slash || slash[1]) { char *redir_uri; - redir_uri = g_strdup_printf ("%s/", soup_message_get_uri (msg)->path); + redir_uri = g_strdup_printf ("%s/", g_uri_get_path (soup_message_get_uri (msg))); soup_message_set_redirect (msg, SOUP_STATUS_MOVED_PERMANENTLY, redir_uri); g_free (redir_uri); @@ -287,10 +287,10 @@ main (int argc, char **argv) uris = soup_server_get_uris (server); for (u = uris; u; u = u->next) { - str = soup_uri_to_string (u->data, FALSE); + str = g_uri_to_string (u->data); g_print ("Listening on %s\n", str); g_free (str); - soup_uri_free (u->data); + g_uri_unref (u->data); } g_slist_free (uris); diff --git a/examples/simple-proxy.c b/examples/simple-proxy.c index eb0433bb..d625c06b 100644 --- a/examples/simple-proxy.c +++ b/examples/simple-proxy.c @@ -209,7 +209,7 @@ static void try_tunnel (SoupServer *server, SoupMessage *msg, SoupClientContext *context) { Tunnel *tunnel; - SoupURI *dest_uri; + GUri *dest_uri; GSocketClient *sclient; soup_server_pause_message (server, msg); @@ -221,7 +221,7 @@ try_tunnel (SoupServer *server, SoupMessage *msg, SoupClientContext *context) dest_uri = soup_message_get_uri (msg); sclient = g_socket_client_new (); - g_socket_client_connect_to_host_async (sclient, dest_uri->host, dest_uri->port, + g_socket_client_connect_to_host_async (sclient, g_uri_get_host (dest_uri), g_uri_get_port (dest_uri), NULL, tunnel_connected_cb, tunnel); g_object_unref (sclient); } @@ -284,7 +284,7 @@ server_callback (SoupServer *server, SoupMessage *msg, SoupMessage *msg2; char *uristr; - uristr = soup_uri_to_string (soup_message_get_uri (msg), FALSE); + uristr = g_uri_to_string (soup_message_get_uri (msg)); g_print ("[%p] %s %s HTTP/1.%d\n", msg, soup_message_get_method (msg), uristr, soup_message_get_http_version (msg)); @@ -398,10 +398,10 @@ main (int argc, char **argv) uris = soup_server_get_uris (server); for (u = uris; u; u = u->next) { - str = soup_uri_to_string (u->data, FALSE); + str = g_uri_to_string (u->data); g_print ("Listening on %s\n", str); g_free (str); - soup_uri_free (u->data); + g_uri_unref (u->data); } g_slist_free (uris); -- cgit v1.2.1