Defs: store the externs as HashMap<AllowedUrl, handle> instead of a String key

Also, make rsvg_handle_load_extern() take a GFile directly.
parent b9b973b4
......@@ -1030,31 +1030,19 @@ rsvg_handle_get_css_styles (RsvgHandle *handle)
}
RsvgHandle *
rsvg_handle_load_extern (RsvgHandle *handle, const char *uri)
rsvg_handle_load_extern (RsvgHandle *handle, GFile *file)
{
RsvgHandle *res = NULL;
GInputStream *stream;
RsvgHandle *res;
stream = rsvg_handle_acquire_stream (handle, uri, NULL);
res = rsvg_handle_new_from_gfile_sync (file,
handle->priv->flags,
NULL,
NULL);
if (stream) {
GFile *file = g_file_new_for_uri (uri);
res = rsvg_handle_new_from_stream_sync (stream,
file,
handle->priv->flags,
NULL,
NULL);
g_object_unref (file);
if (res) {
rsvg_tree_cascade (res->priv->tree);
} else {
/* FIXME: rsvg_log!("could not load external resource"); */
}
g_object_unref (stream);
if (res) {
rsvg_tree_cascade (res->priv->tree);
} else {
/* FIXME: rsvg_log!("could not load external resource"); */
}
return res;
......
......@@ -271,7 +271,7 @@ GFile *rsvg_handle_rust_get_base_gfile (RsvgHandleRust *raw_handle);
G_GNUC_INTERNAL
RsvgHandle *rsvg_handle_load_extern (RsvgHandle *handle,
const char *uri);
GFile *file);
G_GNUC_INTERNAL
gboolean rsvg_handle_keep_image_data (RsvgHandle *handle);
......
......@@ -11,7 +11,7 @@ use url::{self, Url};
/// a specified `href` (a possibly-relative filename, for example)
/// should be allowed to be loaded, given the base URL of the SVG
/// being loaded.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct AllowedUrl(Url);
#[derive(Debug, PartialEq)]
......
......@@ -17,7 +17,7 @@ pub enum RsvgDefs {}
pub struct Defs {
nodes: HashMap<String, Rc<Node>>,
externs: HashMap<String, *const RsvgHandle>,
externs: HashMap<AllowedUrl, *const RsvgHandle>,
}
impl Defs {
......@@ -60,7 +60,7 @@ impl Defs {
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()) {
match self.externs.entry(aurl) {
Entry::Occupied(e) => Ok(*(e.get())),
Entry::Vacant(e) => {
let extern_handle = handle::load_extern(handle, e.key())?;
......
......@@ -41,7 +41,7 @@ extern "C" {
fn rsvg_handle_load_extern(
handle: *const RsvgHandle,
href: *const libc::c_char,
file: *const gio_sys::GFile,
) -> *const RsvgHandle;
fn rsvg_handle_keep_image_data(handle: *const RsvgHandle) -> glib_sys::gboolean;
......@@ -63,9 +63,11 @@ pub fn get_defs<'a>(handle: *const RsvgHandle) -> &'a mut Defs {
}
}
pub fn load_extern(handle: *const RsvgHandle, uri: &str) -> Result<*const RsvgHandle, ()> {
pub fn load_extern(handle: *const RsvgHandle, aurl: &AllowedUrl) -> Result<*const RsvgHandle, ()> {
unsafe {
let res = rsvg_handle_load_extern(handle, uri.to_glib_none().0);
let file = GFile::new_for_uri(aurl.url().as_str());
let res = rsvg_handle_load_extern(handle, file.to_glib_none().0);
if res.is_null() {
Err(())
......
Markdown is supported
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