Commit 98d613be authored by IBBoard's avatar IBBoard Committed by Daniel Garcia Moreno
Browse files

Work with file paths, not URI substrings, in custom URI scheme

Using `…_get_uri()` gives a string that includes the anchor, which
isn't a valid entry path in the archive. `…_get_path()` gets just
the path (but with a leading slash).

Rather than special case the widget code to handle the starting slash,
the archive and doc now ignore the leading slash in paths. This allows
`…_get_path()` to be used anywhere in the code base without additional
text manipulation each time.
parent 6f1f18f6
......@@ -135,12 +135,20 @@ gepub_archive_read_entry (GepubArchive *archive,
struct archive_entry *entry;
guchar *buffer;
gint size;
const gchar *_path;
if (path[0] == '/') {
_path = path + 1;
}
else {
_path = path;
}
if (!gepub_archive_open (archive))
return NULL;
while (archive_read_next_header (archive->archive, &entry) == ARCHIVE_OK) {
if (g_ascii_strcasecmp (path, archive_entry_pathname (entry)) == 0)
if (g_ascii_strcasecmp (_path, archive_entry_pathname (entry)) == 0)
break;
archive_read_data_skip (archive->archive);
}
......
......@@ -595,15 +595,23 @@ gepub_doc_get_resource_mime (GepubDoc *doc, const gchar *path)
{
GepubResource *gres;
GList *keys;
const gchar *_path;
g_return_val_if_fail (GEPUB_IS_DOC (doc), NULL);
g_return_val_if_fail (path != NULL, NULL);
if (path[0] == '/') {
_path = path + 1;
}
else {
_path = path;
}
keys = g_hash_table_get_keys (doc->resources);
while (keys) {
gres = ((GepubResource*)g_hash_table_lookup (doc->resources, keys->data));
if (!strcmp (gres->uri, path))
if (!strcmp (gres->uri, _path))
break;
keys = keys->next;
}
......
......@@ -243,7 +243,6 @@ resource_callback (WebKitURISchemeRequest *request, gpointer user_data)
{
GInputStream *stream;
gchar *path;
gchar *uri;
gchar *mime;
GepubWidget *widget = user_data;
GBytes *contents;
......@@ -251,9 +250,7 @@ resource_callback (WebKitURISchemeRequest *request, gpointer user_data)
if (!widget->doc)
return;
uri = g_strdup (webkit_uri_scheme_request_get_uri (request));
// removing "epub:///"
path = uri + 8;
path = g_strdup (webkit_uri_scheme_request_get_path (request));
contents = gepub_doc_get_resource (widget->doc, path);
mime = gepub_doc_get_resource_mime (widget->doc, path);
......@@ -275,7 +272,7 @@ resource_callback (WebKitURISchemeRequest *request, gpointer user_data)
g_object_unref (stream);
g_bytes_unref (contents);
g_free (mime);
g_free (uri);
g_free (path);
}
static void
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment