[librsvg] Defs::get_extern_handle(): use AllowedUrl instead of rsvg_handle_resolve_uri()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Defs::get_extern_handle(): use AllowedUrl instead of rsvg_handle_resolve_uri()
- Date: Tue, 27 Nov 2018 00:24:43 +0000 (UTC)
commit 85105f739656e0124a94de0093602db5803837c9
Author: Federico Mena Quintero <federico gnome org>
Date: Mon Nov 26 18:01:15 2018 -0600
Defs::get_extern_handle(): use AllowedUrl instead of rsvg_handle_resolve_uri()
This lets us remove that C function.
librsvg/rsvg-handle.c | 34 ----------------------------------
librsvg/rsvg-private.h | 4 ----
rsvg_internals/src/defs.rs | 28 ++++++++++++++--------------
rsvg_internals/src/handle.rs | 24 +++++++-----------------
4 files changed, 21 insertions(+), 69 deletions(-)
---
diff --git a/librsvg/rsvg-handle.c b/librsvg/rsvg-handle.c
index ec6bbc51..bd37c9c9 100644
--- a/librsvg/rsvg-handle.c
+++ b/librsvg/rsvg-handle.c
@@ -1544,40 +1544,6 @@ rsvg_handle_set_size_callback (RsvgHandle * handle,
handle->priv->user_data_destroy = user_data_destroy;
}
-char *
-rsvg_handle_resolve_uri (RsvgHandle *handle,
- const char *uri)
-{
- RsvgHandlePrivate *priv = handle->priv;
- char *scheme, *resolved_uri;
- GFile *base_gfile;
- GFile *base, *resolved;
-
- if (uri == NULL)
- return NULL;
-
- base_gfile = rsvg_handle_rust_get_base_gfile (priv->rust_handle);
-
- scheme = g_uri_parse_scheme (uri);
- if (scheme != NULL ||
- base_gfile == NULL ||
- (base = g_file_get_parent (base_gfile)) == NULL) {
- g_object_unref (base_gfile);
- g_free (scheme);
- return g_strdup (uri);
- }
-
- resolved = g_file_resolve_relative_path (base, uri);
- resolved_uri = g_file_get_uri (resolved);
-
- g_free (scheme);
- g_object_unref (base);
- g_object_unref (base_gfile);
- g_object_unref (resolved);
-
- return resolved_uri;
-}
-
GCancellable *
rsvg_handle_get_cancellable (RsvgHandle *handle)
{
diff --git a/librsvg/rsvg-private.h b/librsvg/rsvg-private.h
index d612dfcc..d69c75dd 100644
--- a/librsvg/rsvg-private.h
+++ b/librsvg/rsvg-private.h
@@ -259,10 +259,6 @@ RsvgCssStyles *rsvg_handle_get_css_styles (RsvgHandle *handle);
G_GNUC_INTERNAL
void rsvg_handle_load_css(RsvgHandle *handle, const char *href);
-G_GNUC_INTERNAL
-char *rsvg_handle_resolve_uri (RsvgHandle *handle,
- const char *uri);
-
/* Implemented in rsvg_internals/src/handle.rs */
G_GNUC_INTERNAL
RsvgHandleRust *rsvg_handle_rust_new (void);
diff --git a/rsvg_internals/src/defs.rs b/rsvg_internals/src/defs.rs
index b743995d..bb2ed34e 100644
--- a/rsvg_internals/src/defs.rs
+++ b/rsvg_internals/src/defs.rs
@@ -4,6 +4,7 @@ use std::collections::HashMap;
use std::ptr;
use std::rc::Rc;
+use allowed_url::AllowedUrl;
use handle::{self, RsvgHandle};
use node::{Node, RsvgNode};
use util::utf8_cstr;
@@ -37,8 +38,8 @@ impl Defs {
match reference {
Reference::PlainUri(_) => None,
Reference::FragmentId(fragment) => self.nodes.get(fragment),
- Reference::UriWithFragmentId(uri, fragment) => {
- match self.get_extern_handle(handle, uri) {
+ Reference::UriWithFragmentId(href, fragment) => {
+ match self.get_extern_handle(handle, href) {
Ok(extern_handle) => handle::get_defs(extern_handle).nodes.get(fragment),
Err(()) => None,
}
@@ -52,19 +53,18 @@ impl Defs {
fn get_extern_handle(
&mut self,
handle: *const RsvgHandle,
- possibly_relative_uri: &str,
+ href: &str,
) -> Result<*const RsvgHandle, ()> {
- match handle::resolve_uri(handle, possibly_relative_uri) {
- None => Err(()),
-
- Some(uri) => match self.externs.entry(uri) {
- Entry::Occupied(e) => Ok(*(e.get())),
- Entry::Vacant(e) => {
- let extern_handle = handle::load_extern(handle, e.key())?;
- e.insert(extern_handle);
- Ok(extern_handle)
- }
- },
+ let aurl =
+ AllowedUrl::from_href(href, handle::get_base_url(handle).as_ref()).map_err(|_| ())?;
+
+ match self.externs.entry(aurl.url().as_str().to_string()) {
+ Entry::Occupied(e) => Ok(*(e.get())),
+ Entry::Vacant(e) => {
+ let extern_handle = handle::load_extern(handle, e.key())?;
+ e.insert(extern_handle);
+ Ok(extern_handle)
+ }
}
}
}
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index e3a62c00..6b74f9ea 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -1,4 +1,4 @@
-use std::cell::RefCell;
+use std::cell::{Ref, RefCell};
use std::ptr;
use cairo::{ImageSurface, Status};
@@ -40,11 +40,6 @@ impl Handle {
extern "C" {
fn rsvg_handle_get_defs(handle: *const RsvgHandle) -> *const RsvgDefs;
- fn rsvg_handle_resolve_uri(
- handle: *const RsvgHandle,
- uri: *const libc::c_char,
- ) -> *const libc::c_char;
-
fn rsvg_handle_load_extern(
handle: *const RsvgHandle,
href: *const libc::c_char,
@@ -77,17 +72,6 @@ pub fn get_defs<'a>(handle: *const RsvgHandle) -> &'a mut Defs {
}
}
-pub fn resolve_uri(handle: *const RsvgHandle, uri: &str) -> Option<String> {
- unsafe {
- let resolved = rsvg_handle_resolve_uri(handle, uri.to_glib_none().0);
- if resolved.is_null() {
- None
- } else {
- Some(from_glib_full(resolved))
- }
- }
-}
-
pub fn load_extern(handle: *const RsvgHandle, uri: &str) -> Result<*const RsvgHandle, ()> {
unsafe {
let res = rsvg_handle_load_extern(handle, uri.to_glib_none().0);
@@ -100,6 +84,12 @@ pub fn load_extern(handle: *const RsvgHandle, uri: &str) -> Result<*const RsvgHa
}
}
+pub fn get_base_url<'a>(handle: *const RsvgHandle) -> Ref<'a, Option<Url>> {
+ let rhandle = get_rust_handle(handle);
+
+ rhandle.base_url.borrow()
+}
+
pub fn get_css_styles<'a>(handle: *const RsvgHandle) -> &'a CssStyles {
unsafe { &*(rsvg_handle_get_css_styles(handle) as *const CssStyles) }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]