[yelp/yelp-3-0] [libyelp] Changing YelpUri API, document/canonical URI



commit dc81e41bf0b876e10423c895314bae872b451adc
Author: Shaun McCance <shaunm gnome org>
Date:   Sat Oct 10 13:36:36 2009 -0500

    [libyelp] Changing YelpUri API, document/canonical URI

 libyelp/yelp-document.c        |   14 ++--
 libyelp/yelp-simple-document.c |   12 +--
 libyelp/yelp-uri.c             |  231 ++++++++++++++++++++++++++--------------
 libyelp/yelp-uri.h             |    7 +-
 libyelp/yelp-view.c            |   18 ++--
 tests/test-uri.c               |   42 ++++++--
 tests/uri/ghelp-docbook-1.test |    8 +-
 tests/uri/ghelp-docbook-2.test |    7 ++
 tests/uri/ghelp-mallard-1.test |    8 +-
 tests/uri/ghelp-mallard-2.test |    8 ++
 tests/uri/man-1.test           |    8 +-
 tests/uri/man-2.test           |    8 +-
 tests/uri/path-docbook-1.test  |    8 +-
 tests/uri/path-docbook-2.test  |    8 ++
 tests/uri/path-mallard-1.test  |    8 +-
 15 files changed, 264 insertions(+), 131 deletions(-)
---
diff --git a/libyelp/yelp-document.c b/libyelp/yelp-document.c
index d464d44..09bfb99 100644
--- a/libyelp/yelp-document.c
+++ b/libyelp/yelp-document.c
@@ -116,7 +116,7 @@ YelpDocument *
 yelp_document_get_for_uri (YelpUri *uri)
 {
     static GHashTable *documents = NULL;
-    gchar *base_uri;
+    gchar *docuri;
     YelpDocument *document = NULL;
 
     if (documents == NULL)
@@ -125,14 +125,14 @@ yelp_document_get_for_uri (YelpUri *uri)
 
     g_return_val_if_fail (yelp_uri_is_resolved (uri), NULL);
 
-    base_uri = yelp_uri_get_base_uri (uri);
-    if (base_uri == NULL)
+    docuri = yelp_uri_get_document_uri (uri);
+    if (docuri == NULL)
 	return NULL;
 
-    document = g_hash_table_lookup (documents, base_uri);
+    document = g_hash_table_lookup (documents, docuri);
 
     if (document != NULL) {
-	g_free (base_uri);
+	g_free (docuri);
 	return g_object_ref (document);
     }
 
@@ -167,11 +167,11 @@ yelp_document_get_for_uri (YelpUri *uri)
     }
 
     if (document != NULL) {
-	g_hash_table_insert (documents, base_uri, document);
+	g_hash_table_insert (documents, docuri, document);
 	return g_object_ref (document);
     }
 
-    g_free (base_uri);
+    g_free (docuri);
     return NULL;
 }
 
diff --git a/libyelp/yelp-simple-document.c b/libyelp/yelp-simple-document.c
index 11b303c..658df0c 100644
--- a/libyelp/yelp-simple-document.c
+++ b/libyelp/yelp-simple-document.c
@@ -42,8 +42,6 @@ struct _Request {
 };
 
 struct _YelpSimpleDocumentPriv {
-    gchar        *base_uri;
-
     GFile        *file;
     GInputStream *stream;
 
@@ -51,6 +49,7 @@ struct _YelpSimpleDocumentPriv {
     gssize        contents_len;
     gssize        contents_read;
     gchar        *mime_type;
+    gboolean      started;
     gboolean      finished;
 
     GSList       *reqs;
@@ -122,6 +121,7 @@ yelp_simple_document_init (YelpSimpleDocument *document)
     document->priv->file = NULL;
     document->priv->stream = NULL;
 
+    document->priv->started = FALSE;
     document->priv->finished = FALSE;
     document->priv->contents = NULL;
     document->priv->mime_type = NULL;
@@ -156,8 +156,6 @@ yelp_simple_document_finalize (GObject *object)
 {
     YelpSimpleDocument *document = YELP_SIMPLE_DOCUMENT (object);
 
-    g_free (document->priv->base_uri);
-
     g_free (document->priv->contents);
     g_free (document->priv->mime_type);
 
@@ -171,7 +169,7 @@ yelp_simple_document_new (YelpUri *uri)
 
     document = (YelpSimpleDocument *) g_object_new (YELP_TYPE_SIMPLE_DOCUMENT, NULL);
 
-    document->priv->base_uri = yelp_uri_get_base_uri (uri);
+    document->priv->file = yelp_uri_get_file (uri);
 
     return (YelpDocument *) document;
 }
@@ -205,8 +203,8 @@ document_request_page (YelpDocument         *document,
 	g_idle_add ((GSourceFunc) document_signal_all, simple);
 	ret = TRUE;
     }
-    else if (simple->priv->file == NULL) {
-	simple->priv->file = g_file_new_for_uri (simple->priv->base_uri);
+    else if (!simple->priv->started) {
+	simple->priv->started = TRUE;
 	g_file_query_info_async (simple->priv->file,
 				 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
 				 G_FILE_QUERY_INFO_NONE,
diff --git a/libyelp/yelp-uri.c b/libyelp/yelp-uri.c
index 88bf1e8..ea0946b 100644
--- a/libyelp/yelp-uri.c
+++ b/libyelp/yelp-uri.c
@@ -32,30 +32,32 @@
 #include "yelp-uri.h"
 #include "yelp-debug.h"
 
-static void           yelp_uri_class_init   (YelpUriClass   *klass);
-static void           yelp_uri_init         (YelpUri        *uri);
-static void           yelp_uri_dispose      (GObject        *object);
-static void           yelp_uri_finalize     (GObject        *object);
-
-static void           resolve_start         (YelpUri        *uri);
-static void           resolve_async         (YelpUri        *uri);
-static gboolean       resolve_final         (YelpUri        *uri);
-
-static void           resolve_file_uri      (YelpUri        *uri);
-static void           resolve_file_path     (YelpUri        *uri);
-static void           resolve_data_dirs     (YelpUri        *uri,
-                                             const gchar   **subdirs,
-                                             const gchar    *docid,
-                                             const gchar    *pageid);
-static void           resolve_ghelp_uri     (YelpUri        *uri);
-static void           resolve_man_uri       (YelpUri        *uri);
-static void           resolve_info_uri      (YelpUri        *uri);
-static void           resolve_page_and_frag (YelpUri        *uri,
-                                             const gchar    *arg);
-static void           resolve_common        (YelpUri        *uri);
-
-static gboolean       is_man_path           (const gchar    *uri,
-                                             const gchar    *encoding);
+static void           yelp_uri_class_init        (YelpUriClass   *klass);
+static void           yelp_uri_init              (YelpUri        *uri);
+static void           yelp_uri_dispose           (GObject        *object);
+static void           yelp_uri_finalize          (GObject        *object);
+
+static void           resolve_start              (YelpUri        *uri);
+static void           resolve_async              (YelpUri        *uri);
+static gboolean       resolve_final              (YelpUri        *uri);
+
+static void           resolve_file_uri           (YelpUri        *uri);
+static void           resolve_file_path          (YelpUri        *uri);
+static void           resolve_data_dirs          (YelpUri        *uri,
+                                                  const gchar   **subdirs,
+                                                  const gchar    *docid,
+                                                  const gchar    *pageid);
+static void           resolve_ghelp_uri          (YelpUri        *uri);
+static void           resolve_man_uri            (YelpUri        *uri);
+static void           resolve_info_uri           (YelpUri        *uri);
+static void           resolve_relative_multipage (YelpUri        *uri);
+static void           resolve_page_and_frag      (YelpUri        *uri,
+                                                  const gchar    *arg);
+static void           resolve_gfile              (YelpUri        *uri,
+                                                  const gchar    *hash);
+
+static gboolean       is_man_path                (const gchar    *uri,
+                                                  const gchar    *encoding);
 
 G_DEFINE_TYPE (YelpUri, yelp_uri, G_TYPE_OBJECT);
 #define GET_PRIV(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), YELP_TYPE_URI, YelpUriPrivate))
@@ -67,7 +69,10 @@ struct _YelpUriPrivate {
     YelpUriDocumentType   doctype;
     YelpUriDocumentType   tmptype;
 
+    gchar                *docuri;
+    gchar                *fulluri;
     GFile                *gfile;
+
     gchar               **search_path;
     gchar                *page_id;
     gchar                *frag_id;
@@ -149,6 +154,8 @@ yelp_uri_finalize (GObject *object)
 {
     YelpUriPrivate *priv = GET_PRIV (object);
 
+    g_free (priv->docuri);
+    g_free (priv->fulluri);
     g_strfreev (priv->search_path);
     g_free (priv->page_id);
     g_free (priv->frag_id);
@@ -251,16 +258,21 @@ resolve_async (YelpUri *uri)
     else if (g_str_has_prefix (priv->res_arg, "info:")) {
         resolve_info_uri (uri);
     }
+    else if (strchr (priv->res_arg, ':')) {
+        priv->tmptype = YELP_URI_DOCUMENT_TYPE_EXTERNAL;
+        /* FIXME: resolve as external URI */
+    }
+    else if (strchr (priv->res_arg, '/')) {
+        resolve_file_path (uri);
+    }
     else if (priv->res_base != NULL) {
         YelpUriPrivate *base_priv = GET_PRIV (priv->res_base);
         switch (base_priv->doctype) {
         case YELP_URI_DOCUMENT_TYPE_UNRESOLVED:
             break;
         case YELP_URI_DOCUMENT_TYPE_DOCBOOK:
-            /* FIXME: set page_id and frag_id */
-            break;
         case YELP_URI_DOCUMENT_TYPE_MALLARD:
-            /* FIXME: set page_id and frag_id */
+            resolve_relative_multipage (uri);
             break;
         case YELP_URI_DOCUMENT_TYPE_MAN:
             /* FIXME: what do we do? */
@@ -318,30 +330,6 @@ resolve_final (YelpUri *uri)
     return FALSE;
 }
 
-/*
-YelpUri *
-yelp_uri_resolve_relative (YelpUri *base, const gchar *arg)
-{
-    YelpUri *ret;
-    YelpUriPrivate *priv;
-
-    ret = (YelpUri *) g_object_new (YELP_TYPE_URI, NULL);
-    priv = GET_PRIV (ret);
-    priv->doctype = YELP_URI_DOCUMENT_TYPE_UNKNOWN;
-
-    else if (strchr (arg, ':')) {
-        priv->doctype = YELP_URI_DOCUMENT_TYPE_EXTERNAL;
-        priv->gfile = g_file_new_for_uri (arg);
-        TRUE;
-    }
-    else {
-        resolve_file_path (ret, base, arg);
-    }
-
-    return ret;
-}
-*/
-
 /******************************************************************************/
 
 gboolean
@@ -359,12 +347,30 @@ yelp_uri_get_document_type (YelpUri *uri)
 }
 
 gchar *
-yelp_uri_get_base_uri (YelpUri *uri)
+yelp_uri_get_document_uri (YelpUri *uri)
+{
+    YelpUriPrivate *priv = GET_PRIV (uri);
+    if (priv->doctype == YELP_URI_DOCUMENT_TYPE_UNRESOLVED)
+        return NULL;
+    return g_strdup (priv->docuri);
+}
+
+gchar *
+yelp_uri_get_canonical_uri (YelpUri *uri)
 {
     YelpUriPrivate *priv = GET_PRIV (uri);
     if (priv->doctype == YELP_URI_DOCUMENT_TYPE_UNRESOLVED)
         return NULL;
-    return priv->gfile ? g_file_get_uri (priv->gfile) : NULL;
+    return g_strdup (priv->fulluri);
+}
+
+GFile *
+yelp_uri_get_file (YelpUri *uri)
+{
+    YelpUriPrivate *priv = GET_PRIV (uri);
+    if (priv->doctype == YELP_URI_DOCUMENT_TYPE_UNRESOLVED)
+        return NULL;
+    return priv->gfile ? g_object_ref (priv->gfile) : NULL;
 }
 
 gchar **
@@ -403,19 +409,16 @@ resolve_file_uri (YelpUri *uri)
     gchar *uristr;
     const gchar *hash = strchr (priv->res_arg, '#');
 
-    if (hash)
+    if (hash) {
         uristr = g_strndup (priv->res_arg, hash - priv->res_arg);
+        hash++;
+    }
     else
         uristr = priv->res_arg;
 
     priv->gfile = g_file_new_for_uri (uristr);
 
-    if (hash) {
-        resolve_page_and_frag (uri, hash + 1);
-        g_free (uristr);
-    }
-
-    resolve_common (uri);
+    resolve_gfile (uri, hash);
 }
 
 static void
@@ -429,8 +432,10 @@ resolve_file_path (YelpUri *uri)
     if (priv->res_base)
         base_priv = GET_PRIV (priv->res_base);
 
-    if (hash)
+    if (hash) {
         path = g_strndup (priv->res_arg, hash - priv->res_arg);
+        hash++;
+    }
     else
         path = priv->res_arg;
 
@@ -450,12 +455,7 @@ resolve_file_path (YelpUri *uri)
         g_free (cur);
     }
 
-    if (hash) {
-        resolve_page_and_frag (uri, hash + 1);
-        g_free (path);
-    }
-
-    resolve_common (uri);
+    resolve_gfile (uri, hash);
 }
 
 static void
@@ -606,6 +606,17 @@ resolve_ghelp_uri (YelpUri *uri)
         priv->frag_id = g_strdup (hash);
     }
 
+    priv->docuri = g_strconcat ("ghelp:", document,
+                                slash ? "/" : NULL,
+                                slash, NULL);
+
+    priv->fulluri = g_strconcat (priv->docuri,
+                                 priv->page_id ? "?" : "",
+                                 priv->page_id ? priv->page_id : "",
+                                 priv->frag_id ? "#" : "",
+                                 priv->frag_id ? priv->frag_id : "",
+                                 NULL);
+
     g_free (document);
     g_free (slash);
     return;
@@ -628,6 +639,7 @@ resolve_man_uri (YelpUri *uri)
     gchar *fullpath = NULL;
 
     /* not to be freed */
+    gchar *realsection;
     gchar *colon, *hash;
     gchar *lbrace = NULL;
     gchar *rbrace = NULL;
@@ -697,35 +709,34 @@ resolve_man_uri (YelpUri *uri)
             }
 
             for (k = 0; section ? k == 0 : mancats[k] != NULL; k++) {
-                gchar *sectiondir;
                 if (section)
-                    sectiondir = g_strconcat ("man", section, NULL);
+                    realsection = section;
                 else
-                    sectiondir = g_strconcat ("man", mancats[k], NULL);
+                    realsection = mancats[k];
 
-                fullpath = g_strconcat (langdir, "/", sectiondir,
-                                        "/", name, ".", sectiondir + 3,
+                fullpath = g_strconcat (langdir, "/man", realsection,
+                                        "/", name, ".", realsection,
                                         NULL);
                 if (g_file_test (fullpath, G_FILE_TEST_IS_REGULAR))
                     goto gotit;
                 g_free (fullpath);
 
-                fullpath = g_strconcat (langdir, "/", sectiondir,
-                                        "/", name, ".", sectiondir + 3, ".gz",
+                fullpath = g_strconcat (langdir, "/man", realsection,
+                                        "/", name, ".", realsection, ".gz",
                                         NULL);
                 if (g_file_test (fullpath, G_FILE_TEST_IS_REGULAR))
                     goto gotit;
                 g_free (fullpath);
 
-                fullpath = g_strconcat (langdir, "/", sectiondir,
-                                        "/", name, ".", sectiondir + 3, ".bz2",
+                fullpath = g_strconcat (langdir, "/man", realsection,
+                                        "/", name, ".", realsection, ".bz2",
                                         NULL);
                 if (g_file_test (fullpath, G_FILE_TEST_IS_REGULAR))
                     goto gotit;
                 g_free (fullpath);
 
-                fullpath = g_strconcat (langdir, "/", sectiondir,
-                                        "/", name, ".", sectiondir + 3, ".lzma",
+                fullpath = g_strconcat (langdir, "/man", realsection,
+                                        "/", name, ".", realsection, ".lzma",
                                         NULL);
                 if (g_file_test (fullpath, G_FILE_TEST_IS_REGULAR))
                     goto gotit;
@@ -733,7 +744,6 @@ resolve_man_uri (YelpUri *uri)
 
                 fullpath = NULL;
             gotit:
-                g_free (sectiondir);
                 if (fullpath)
                     break;
             }
@@ -748,7 +758,9 @@ resolve_man_uri (YelpUri *uri)
     if (fullpath) {
         priv->tmptype = YELP_URI_DOCUMENT_TYPE_MAN;
         priv->gfile = g_file_new_for_path (fullpath);
-        resolve_common (uri);
+        priv->docuri = g_strconcat ("man:",  name, ".", realsection, NULL);
+        priv->fulluri = g_strdup (priv->docuri);
+        resolve_gfile (uri, NULL);
         g_free (fullpath);
     } else {
         priv->tmptype = YELP_URI_DOCUMENT_TYPE_NOT_FOUND;
@@ -767,6 +779,42 @@ resolve_info_uri (YelpUri *uri)
 }
 
 static void
+resolve_relative_multipage (YelpUri *uri)
+{
+    YelpUriPrivate *priv = GET_PRIV (uri);
+    YelpUriPrivate *base_priv = GET_PRIV (priv->res_base);
+
+    priv->tmptype = base_priv->doctype;
+    priv->gfile = g_object_ref (base_priv->gfile);
+    priv->search_path = g_strdupv (base_priv->search_path);
+    priv->docuri = g_strdup (base_priv->docuri);
+
+    if (priv->res_arg[0] == '#') {
+        priv->page_id = g_strdup (base_priv->page_id);
+        priv->frag_id = g_strdup (priv->res_arg + 1);
+    }
+    else {
+        gchar *hash = strchr (priv->res_arg, '#');
+        if (hash) {
+            priv->page_id = g_strndup (priv->res_arg, hash - priv->res_arg);
+            priv->frag_id = g_strdup (hash + 1);
+        }
+        else {
+            priv->page_id = g_strdup (priv->res_arg);
+            priv->frag_id = NULL;
+        }
+    }
+
+    /* FIXME: ONLY FOR ghelp */
+    priv->fulluri = g_strconcat (priv->docuri,
+                                 priv->page_id ? "?" : "",
+                                 priv->page_id ? priv->page_id : "",
+                                 priv->frag_id ? "#" : "",
+                                 priv->frag_id ? priv->frag_id : "",
+                                 NULL);
+}
+
+static void
 resolve_page_and_frag (YelpUri *uri, const gchar *arg)
 {
     YelpUriPrivate *priv = GET_PRIV (uri);
@@ -787,7 +835,7 @@ resolve_page_and_frag (YelpUri *uri, const gchar *arg)
 }
 
 static void
-resolve_common (YelpUri *uri)
+resolve_gfile (YelpUri *uri, const gchar *hash)
 {
     YelpUriPrivate *priv = GET_PRIV (uri);
     GFileInfo *info;
@@ -834,12 +882,20 @@ resolve_common (YelpUri *uri)
                 g_str_equal (mime_type, "application/docbook+xml") ||
                 g_str_equal (mime_type, "application/xml")) {
                 priv->tmptype = YELP_URI_DOCUMENT_TYPE_DOCBOOK;
+                if (priv->page_id == NULL)
+                    priv->page_id = g_strdup (hash);
+                if (priv->frag_id == NULL)
+                    priv->frag_id = g_strdup (hash);
             }
             else if (g_str_equal (mime_type, "text/html")) {
                 priv->tmptype = YELP_URI_DOCUMENT_TYPE_HTML;
+                if (priv->frag_id == NULL)
+                    priv->frag_id = g_strdup (hash);
             }
             else if (g_str_equal (mime_type, "application/xhtml+xml")) {
                 priv->tmptype = YELP_URI_DOCUMENT_TYPE_XHTML;
+                if (priv->frag_id == NULL)
+                    priv->frag_id = g_strdup (hash);
             }
             else if (g_str_equal (mime_type, "application/x-gzip")) {
                 if (g_str_has_suffix (basename, ".info.gz"))
@@ -872,12 +928,25 @@ resolve_common (YelpUri *uri)
                     priv->tmptype = YELP_URI_DOCUMENT_TYPE_MAN;
                 else
                     priv->tmptype = YELP_URI_DOCUMENT_TYPE_TEXT;
+                if (priv->frag_id == NULL)
+                    priv->frag_id = g_strdup (hash);
             }
             else {
                 priv->tmptype = YELP_URI_DOCUMENT_TYPE_EXTERNAL;
             }
         }
     }
+
+    if (priv->docuri == NULL)
+        priv->docuri = g_file_get_uri (priv->gfile);
+
+    if (priv->fulluri == NULL)
+        priv->fulluri = g_strconcat (priv->docuri,
+                                     (priv->page_id || priv->frag_id) ? "#" : NULL,
+                                     priv->page_id ? priv->page_id : priv->frag_id,
+                                     NULL);
+
+    g_object_unref (info);
 }
 
 static gboolean
diff --git a/libyelp/yelp-uri.h b/libyelp/yelp-uri.h
index b44d2c8..09bf40d 100644
--- a/libyelp/yelp-uri.h
+++ b/libyelp/yelp-uri.h
@@ -72,7 +72,12 @@ void                 yelp_uri_resolve            (YelpUri      *uri);
 
 gboolean             yelp_uri_is_resolved        (YelpUri      *uri);
 YelpUriDocumentType  yelp_uri_get_document_type  (YelpUri      *uri);
-gchar *              yelp_uri_get_base_uri       (YelpUri      *uri);
+
+gchar *              yelp_uri_get_canonical_uri  (YelpUri      *uri);
+gchar *              yelp_uri_get_document_uri   (YelpUri      *uri);
+
+GFile *              yelp_uri_get_file           (YelpUri      *uri);
+
 gchar **             yelp_uri_get_search_path    (YelpUri      *uri);
 gchar *              yelp_uri_get_page_id        (YelpUri      *uri);
 gchar *              yelp_uri_get_frag_id        (YelpUri      *uri);
diff --git a/libyelp/yelp-view.c b/libyelp/yelp-view.c
index 36f4ed5..8bf6436 100644
--- a/libyelp/yelp-view.c
+++ b/libyelp/yelp-view.c
@@ -287,15 +287,15 @@ view_load_page (YelpView *view)
 
     if (priv->document == NULL) {
         GError *error;
-        gchar *base_uri;
+        gchar *docuri;
         /* FIXME: and if priv->uri is NULL? */
-        base_uri = yelp_uri_get_base_uri (priv->uri);
+        docuri = yelp_uri_get_document_uri (priv->uri);
         /* FIXME: CANT_READ isn't right */
-        if (base_uri) {
+        if (docuri) {
             error = g_error_new (YELP_ERROR, YELP_ERROR_CANT_READ,
                                  _("Could not load a document for â??%sâ??"),
-                                 base_uri);
-            g_free (base_uri);
+                                 docuri);
+            g_free (docuri);
         }
         else {
             error = g_error_new (YELP_ERROR, YELP_ERROR_CANT_READ,
@@ -396,19 +396,19 @@ document_callback (YelpDocument       *document,
     }
     else if (signal == YELP_DOCUMENT_SIGNAL_CONTENTS) {
 	const gchar *contents = yelp_document_read_contents (document, NULL);
-        gchar *base_uri, *mime_type, *page_id;
-        base_uri = yelp_uri_get_base_uri (priv->uri);
+        gchar *real_uri, *mime_type, *page_id;
+        real_uri = yelp_uri_get_canonical_uri (priv->uri);
         page_id = yelp_uri_get_page_id (priv->uri);
         mime_type = yelp_document_get_mime_type (document, page_id);
         webkit_web_view_load_string (WEBKIT_WEB_VIEW (view),
                                      contents,
                                      mime_type,
                                      "UTF-8",
-                                     base_uri);
+                                     real_uri);
         g_object_set (view, "state", YELP_VIEW_STATE_LOADED, NULL);
         g_free (page_id);
         g_free (mime_type);
-        g_free (base_uri);
+        g_free (real_uri);
 	yelp_document_finish_read (document, contents);
     }
     else if (signal == YELP_DOCUMENT_SIGNAL_ERROR) {
diff --git a/tests/test-uri.c b/tests/test-uri.c
index 96f9d5e..fad73e8 100644
--- a/tests/test-uri.c
+++ b/tests/test-uri.c
@@ -34,6 +34,7 @@ GMainLoop *loop;
 static void 
 print_uri (YelpUri *uri, GOutputStream *stream)
 {
+    GFile *file;
     gchar *type, *tmp, **tmpv, *out;
 
     switch (yelp_uri_get_document_type (uri)) {
@@ -78,26 +79,44 @@ print_uri (YelpUri *uri, GOutputStream *stream)
         break;
     }
 
-    out = g_strdup_printf ("TYPE:  %s\n", type);
+    out = g_strdup_printf ("DOCUMENT TYPE: %s\n", type);
     g_output_stream_write (stream, out, strlen (out), NULL, NULL);
     g_free (out);
 
-    tmp = yelp_uri_get_base_uri (uri);
+    tmp = yelp_uri_get_document_uri (uri);
     if (tmp) {
-        out = g_strdup_printf ("URI:   %s\n", tmp);
+        out = g_strdup_printf ("DOCUMENT URI:  %s\n", tmp);
         g_output_stream_write (stream, out, strlen (out), NULL, NULL);
         g_free (out);
         g_free (tmp);
     }
 
+    tmp = yelp_uri_get_canonical_uri (uri);
+    if (tmp) {
+        out = g_strdup_printf ("CANONICAL URI: %s\n", tmp);
+        g_output_stream_write (stream, out, strlen (out), NULL, NULL);
+        g_free (out);
+        g_free (tmp);
+    }
+
+    file = yelp_uri_get_file (uri);
+    if (file) {
+        tmp = g_file_get_uri (file);
+        out = g_strdup_printf ("FILE URI:      %s\n", tmp);
+        g_output_stream_write (stream, out, strlen (out), NULL, NULL);
+        g_free (out);
+        g_free (tmp);
+        g_object_unref (file);
+    }
+
     tmpv = yelp_uri_get_search_path (uri);
     if (tmpv) {
         int i;
         for (i = 0; tmpv[i]; i++) {
             if (i == 0)
-                out = g_strdup_printf ("PATH:  %s\n", tmpv[i]);
+                out = g_strdup_printf ("SEARCH PATH:   %s\n", tmpv[i]);
             else
-                out = g_strdup_printf ("       %s\n", tmpv[i]);
+                out = g_strdup_printf ("               %s\n", tmpv[i]);
             g_output_stream_write (stream, out, strlen (out), NULL, NULL);
             g_free (out);
         }
@@ -106,7 +125,7 @@ print_uri (YelpUri *uri, GOutputStream *stream)
 
     tmp = yelp_uri_get_page_id (uri);
     if (tmp) {
-        out = g_strdup_printf ("PAGE:  %s\n", tmp);
+        out = g_strdup_printf ("PAGE ID:       %s\n", tmp);
         g_output_stream_write (stream, out, strlen (out), NULL, NULL);
         g_free (out);
         g_free (tmp);
@@ -114,7 +133,7 @@ print_uri (YelpUri *uri, GOutputStream *stream)
 
     tmp = yelp_uri_get_frag_id (uri);
     if (tmp) {
-        out = g_strdup_printf ("FRAG:  %s\n", tmp);
+        out = g_strdup_printf ("FRAG ID:       %s\n", tmp);
         g_output_stream_write (stream, out, strlen (out), NULL, NULL);
         g_free (out);
         g_free (tmp);
@@ -127,6 +146,7 @@ static void run_test (gconstpointer data)
     gchar contents[1024];
     gsize bytes;
     gchar *curi, *newline;
+    gchar **uriv;
     GFile *file = G_FILE (data);
     YelpUri *uri;
     GOutputStream *outstream;
@@ -138,7 +158,13 @@ static void run_test (gconstpointer data)
                                        NULL, NULL));
     newline = strchr (contents, '\n');
     curi = g_strndup (contents, newline - contents);
-    uri = yelp_uri_new (curi);
+    uriv = g_strsplit (curi, " ", 2);
+    g_free (curi);
+    uri = yelp_uri_new (uriv[0]);
+    if (uriv[1] != NULL)
+        uri = yelp_uri_new_relative (uri, uriv[1]);
+    g_strfreev (uriv);
+
     yelp_uri_resolve (uri);
 
     while (!yelp_uri_is_resolved (uri))
diff --git a/tests/uri/ghelp-docbook-1.test b/tests/uri/ghelp-docbook-1.test
index c52d19a..9582c6b 100644
--- a/tests/uri/ghelp-docbook-1.test
+++ b/tests/uri/ghelp-docbook-1.test
@@ -1,4 +1,6 @@
 ghelp:user-guide
-TYPE:  DOCBOOK
-URI:   file:///usr/share/gnome/help/user-guide/C/user-guide.xml
-PATH:  /usr/share/gnome/help/user-guide/C
+DOCUMENT TYPE: DOCBOOK
+DOCUMENT URI:  ghelp:user-guide
+CANONICAL URI: ghelp:user-guide
+FILE URI:      file:///usr/share/gnome/help/user-guide/C/user-guide.xml
+SEARCH PATH:   /usr/share/gnome/help/user-guide/C
diff --git a/tests/uri/ghelp-docbook-2.test b/tests/uri/ghelp-docbook-2.test
new file mode 100644
index 0000000..cf96c42
--- /dev/null
+++ b/tests/uri/ghelp-docbook-2.test
@@ -0,0 +1,7 @@
+ghelp:user-guide gosnautilus
+DOCUMENT TYPE: DOCBOOK
+DOCUMENT URI:  ghelp:user-guide
+CANONICAL URI: ghelp:user-guide?gosnautilus
+FILE URI:      file:///usr/share/gnome/help/user-guide/C/user-guide.xml
+SEARCH PATH:   /usr/share/gnome/help/user-guide/C
+PAGE ID:       gosnautilus
diff --git a/tests/uri/ghelp-mallard-1.test b/tests/uri/ghelp-mallard-1.test
index bbb9a24..cb34b2e 100644
--- a/tests/uri/ghelp-mallard-1.test
+++ b/tests/uri/ghelp-mallard-1.test
@@ -1,4 +1,6 @@
 ghelp:gnome-doc-mallard-spec
-TYPE:  MALLARD
-URI:   file:///usr/share/gnome/help/gnome-doc-mallard-spec/C
-PATH:  /usr/share/gnome/help/gnome-doc-mallard-spec/C
+DOCUMENT TYPE: MALLARD
+DOCUMENT URI:  ghelp:gnome-doc-mallard-spec
+CANONICAL URI: ghelp:gnome-doc-mallard-spec
+FILE URI:      file:///usr/share/gnome/help/gnome-doc-mallard-spec/C
+SEARCH PATH:   /usr/share/gnome/help/gnome-doc-mallard-spec/C
diff --git a/tests/uri/ghelp-mallard-2.test b/tests/uri/ghelp-mallard-2.test
new file mode 100644
index 0000000..9b2dd03
--- /dev/null
+++ b/tests/uri/ghelp-mallard-2.test
@@ -0,0 +1,8 @@
+ghelp:gnome-doc-mallard-spec mal_block#basic
+DOCUMENT TYPE: MALLARD
+DOCUMENT URI:  ghelp:gnome-doc-mallard-spec
+CANONICAL URI: ghelp:gnome-doc-mallard-spec?mal_block#basic
+FILE URI:      file:///usr/share/gnome/help/gnome-doc-mallard-spec/C
+SEARCH PATH:   /usr/share/gnome/help/gnome-doc-mallard-spec/C
+PAGE ID:       mal_block
+FRAG ID:       basic
diff --git a/tests/uri/man-1.test b/tests/uri/man-1.test
index 84851e6..beead01 100644
--- a/tests/uri/man-1.test
+++ b/tests/uri/man-1.test
@@ -1,4 +1,6 @@
 man:flac
-TYPE:  MAN
-URI:   file:///usr/share/man/man1/flac.1.gz
-PATH:  /usr/share/man/man1
+DOCUMENT TYPE: MAN
+DOCUMENT URI:  man:flac.1
+CANONICAL URI: man:flac.1
+FILE URI:      file:///usr/share/man/man1/flac.1.gz
+SEARCH PATH:   /usr/share/man/man1
diff --git a/tests/uri/man-2.test b/tests/uri/man-2.test
index 19e1466..6110cc9 100644
--- a/tests/uri/man-2.test
+++ b/tests/uri/man-2.test
@@ -1,4 +1,6 @@
 man:echo.1p
-TYPE:  MAN
-URI:   file:///usr/share/man/man1p/echo.1p.gz
-PATH:  /usr/share/man/man1p
+DOCUMENT TYPE: MAN
+DOCUMENT URI:  man:echo.1p
+CANONICAL URI: man:echo.1p
+FILE URI:      file:///usr/share/man/man1p/echo.1p.gz
+SEARCH PATH:   /usr/share/man/man1p
diff --git a/tests/uri/path-docbook-1.test b/tests/uri/path-docbook-1.test
index 9d8169c..d157a1a 100644
--- a/tests/uri/path-docbook-1.test
+++ b/tests/uri/path-docbook-1.test
@@ -1,4 +1,6 @@
 /usr/share/gnome/help/user-guide/C/user-guide.xml
-TYPE:  DOCBOOK
-URI:   file:///usr/share/gnome/help/user-guide/C/user-guide.xml
-PATH:  /usr/share/gnome/help/user-guide/C
+DOCUMENT TYPE: DOCBOOK
+DOCUMENT URI:  file:///usr/share/gnome/help/user-guide/C/user-guide.xml
+CANONICAL URI: file:///usr/share/gnome/help/user-guide/C/user-guide.xml
+FILE URI:      file:///usr/share/gnome/help/user-guide/C/user-guide.xml
+SEARCH PATH:   /usr/share/gnome/help/user-guide/C
diff --git a/tests/uri/path-docbook-2.test b/tests/uri/path-docbook-2.test
new file mode 100644
index 0000000..43c095e
--- /dev/null
+++ b/tests/uri/path-docbook-2.test
@@ -0,0 +1,8 @@
+/usr/share/gnome/help/user-guide/C/user-guide.xml#gosnautilus
+DOCUMENT TYPE: DOCBOOK
+DOCUMENT URI:  file:///usr/share/gnome/help/user-guide/C/user-guide.xml
+CANONICAL URI: file:///usr/share/gnome/help/user-guide/C/user-guide.xml#gosnautilus
+FILE URI:      file:///usr/share/gnome/help/user-guide/C/user-guide.xml
+SEARCH PATH:   /usr/share/gnome/help/user-guide/C
+PAGE ID:       gosnautilus
+FRAG ID:       gosnautilus
diff --git a/tests/uri/path-mallard-1.test b/tests/uri/path-mallard-1.test
index e51251d..a5e889f 100644
--- a/tests/uri/path-mallard-1.test
+++ b/tests/uri/path-mallard-1.test
@@ -1,4 +1,6 @@
 /usr/share/gnome/help/gnome-doc-mallard-spec/C/
-TYPE:  MALLARD
-URI:   file:///usr/share/gnome/help/gnome-doc-mallard-spec/C
-PATH:  /usr/share/gnome/help/gnome-doc-mallard-spec/C
+DOCUMENT TYPE: MALLARD
+DOCUMENT URI:  file:///usr/share/gnome/help/gnome-doc-mallard-spec/C
+CANONICAL URI: file:///usr/share/gnome/help/gnome-doc-mallard-spec/C
+FILE URI:      file:///usr/share/gnome/help/gnome-doc-mallard-spec/C
+SEARCH PATH:   /usr/share/gnome/help/gnome-doc-mallard-spec/C



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