[yelp/carlosgc/guri: 6/6] Use GUri instead of SoupURI




commit 2bbc816bda0d60349d49a5b7ef9532490f80ab3b
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Thu Mar 18 17:29:20 2021 +0100

    Use GUri instead of SoupURI
    
    This removes the direct dependency on libsoup, so that yelp doesn't need
    to be migrated to libsoup3.

 configure.ac               |  2 +-
 libyelp/yelp-uri-builder.c | 64 ++++++++++++++++++++++++++++------------------
 libyelp/yelp-uri-builder.h |  3 +--
 libyelp/yelp-view.c        | 28 +++++++++++++++-----
 4 files changed, 62 insertions(+), 35 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 89244242..910d0b73 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,7 +26,7 @@ APPSTREAM_XML
 LT_LIB_M
 PKG_CHECK_MODULES(YELP,
 [
-       gio-2.0 >= 2.38.0
+       gio-2.0 >= 2.67.4
        gio-unix-2.0
        gtk+-unix-print-3.0
        gtk+-3.0 >= 3.13.3
diff --git a/libyelp/yelp-uri-builder.c b/libyelp/yelp-uri-builder.c
index 7f1829d3..9a8bdcf7 100644
--- a/libyelp/yelp-uri-builder.c
+++ b/libyelp/yelp-uri-builder.c
@@ -26,45 +26,59 @@
 gchar *
 build_network_uri (const gchar *uri)
 {
-    SoupURI *soup_uri;
-    gchar *bogus_scheme, *path, *retval;
+    GUri *guri, *network_uri;
+    gchar *bogus_scheme;
+    gchar *path = NULL;
+    gchar *retval;
+    const gchar *scheme;
+    const char *fragment;
 
-    soup_uri = soup_uri_new (uri);
+    scheme = g_uri_peek_scheme (uri);
 
     /* Don't mangle URIs for local files */
-    if (soup_uri->scheme == SOUP_URI_SCHEME_FILE)
+    if (g_str_equal (scheme, "file"))
         return g_strdup (uri);
 
+    /* We need to use a different scheme from help or ghelp to be able to deal
+       with absolute uris in the HTML. Help uri schemes are help:gnome-help/...
+       they dont have a slash after the colon so WebKit resolves them as a relative
+       url when they are not. This doesn't happen if the current page URI has a different
+       scheme from absolute uri scheme.
+    */
+    bogus_scheme = build_network_scheme (scheme);
+
+    guri = g_uri_parse (uri, G_URI_FLAGS_ENCODED, NULL);
+    fragment = g_uri_get_fragment (guri);
+
     /* Build the URI that will be passed to WebKit. Relative URIs will be
      * automatically resolved by WebKit, so we need to add a leading slash to
      * help: and ghelp: URIs to be considered as absolute by WebKit.
      */
-    if (g_str_equal (soup_uri->scheme, "ghelp") || g_str_equal (soup_uri->scheme, "gnome-help") ||
-        g_str_equal (soup_uri->scheme, "help") || g_str_equal (soup_uri->scheme, "help-list") ||
-        g_str_equal (soup_uri->scheme, "info") || g_str_equal (soup_uri->scheme, "man")) {
-
-        if (g_str_equal (soup_uri->scheme, "info") && soup_uri->fragment) {
-            path = g_strdup_printf ("/%s/%s", soup_uri->path, soup_uri->fragment);
-            soup_uri_set_fragment (soup_uri, NULL);
+    if (g_str_equal (scheme, "ghelp") || g_str_equal (scheme, "gnome-help") ||
+        g_str_equal (scheme, "help") || g_str_equal (scheme, "help-list") ||
+        g_str_equal (scheme, "info") || g_str_equal (scheme, "man")) {
+        if (g_str_equal (scheme, "info") && fragment) {
+            path = g_strdup_printf ("/%s/%s", g_uri_get_path (guri), fragment);
+            fragment = NULL;
         } else {
-            path = g_strdup_printf ("/%s", soup_uri->path);
+            path = g_strdup_printf ("/%s", g_uri_get_path (guri));
         }
-        soup_uri_set_path (soup_uri, path);
-        g_free (path);
     }
 
-    /* We need to use a different scheme from help or ghelp to be able to deal
-       with absolute uris in the HTML. Help uri schemes are help:gnome-help/...
-       they dont have a slash after the colon so WebKit resolves them as a relative
-       url when they are not. This doesn't happen if the current page URI has a different
-       scheme from absolute uri scheme.
-    */
-    bogus_scheme = build_network_scheme (soup_uri->scheme);
-    soup_uri_set_scheme (soup_uri, bogus_scheme);
-
-    retval = soup_uri_to_string (soup_uri, FALSE);
-    soup_uri_free (soup_uri);
+    network_uri = g_uri_build (g_uri_get_flags (guri),
+                               bogus_scheme,
+                               g_uri_get_userinfo (guri),
+                               g_uri_get_host (guri),
+                               g_uri_get_port (guri),
+                               path ? path : g_uri_get_path (guri),
+                               g_uri_get_query (guri),
+                               fragment);
     g_free (bogus_scheme);
+    g_free (path);
+    g_uri_unref (guri);
+
+    retval = g_uri_to_string (network_uri);
+    g_uri_unref (network_uri);
 
     return retval;
 }
diff --git a/libyelp/yelp-uri-builder.h b/libyelp/yelp-uri-builder.h
index d6effa4c..049b9a03 100644
--- a/libyelp/yelp-uri-builder.h
+++ b/libyelp/yelp-uri-builder.h
@@ -19,10 +19,9 @@
  */
 
 #include <string.h>
-#include <libsoup/soup.h>
 
 #include "yelp-uri.h"
 
 gchar * build_network_uri    (const gchar *uri);
 gchar * build_yelp_uri       (const gchar *uri);
-gchar * build_network_scheme (const gchar *scheme);
\ No newline at end of file
+gchar * build_network_scheme (const gchar *scheme);
diff --git a/libyelp/yelp-view.c b/libyelp/yelp-view.c
index b4ac84e1..1f10000c 100644
--- a/libyelp/yelp-view.c
+++ b/libyelp/yelp-view.c
@@ -1847,11 +1847,12 @@ view_clear_load (YelpView *view)
 static gchar*
 fix_docbook_uri (YelpUri *docbook_uri, YelpDocument* document)
 {
-    SoupURI *soup_uri;
+    GUri *uri;
     gchar *retval, *canonical;
+    const gchar *fragment;
 
     canonical = yelp_uri_get_canonical_uri (docbook_uri);
-    soup_uri = soup_uri_new (canonical);
+    uri = g_uri_parse (canonical, G_URI_FLAGS_ENCODED, NULL);
     g_free (canonical);
 
     /* We don't have actual page and frag IDs for DocBook. We just map IDs
@@ -1859,19 +1860,32 @@ fix_docbook_uri (YelpUri *docbook_uri, YelpDocument* document)
        If someid is really the page ID, we just drop the frag reference.
        Otherwise, normal page views scroll past the link trail.
     */
-    if (soup_uri->fragment && YELP_IS_DOCBOOK_DOCUMENT (document)) {
+    fragment = g_uri_get_fragment (uri);
+    if (fragment && YELP_IS_DOCBOOK_DOCUMENT (document)) {
         gchar *page_id = yelp_uri_get_page_id (docbook_uri);
         gchar *real_id = yelp_document_get_page_id (document, page_id);
 
-        if (g_str_equal (real_id, soup_uri->fragment))
-            soup_uri_set_fragment (soup_uri, NULL);
+        if (g_str_equal (real_id, fragment)) {
+            GUri *modified;
+
+            modified = g_uri_build (g_uri_get_flags (uri),
+                                    g_uri_get_scheme (uri),
+                                    g_uri_get_userinfo (uri),
+                                    g_uri_get_host (uri),
+                                    g_uri_get_port (uri),
+                                    g_uri_get_path (uri),
+                                    g_uri_get_query (uri),
+                                    NULL);
+            g_uri_unref (uri);
+            uri = modified;
+        }
 
         g_free (real_id);
         g_free (page_id);
     }
 
-    retval = soup_uri_to_string (soup_uri, FALSE);
-    soup_uri_free (soup_uri);
+    retval = g_uri_to_string (uri);
+    g_uri_unref (uri);
 
     return retval;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]