Commit cf1c41c9 authored by Christian Persch's avatar Christian Persch

Obey the passed-in cancellable

Add GCancellable argument to _rsvg_io_acquire_*, and pass the
cancellable passed to rsvg_handle_read_stream_sync() down.
parent c72df0b0
......@@ -93,7 +93,7 @@ rsvg_handle_new_from_file (const gchar * file_name, GError ** error)
rsvg_return_val_if_fail (file_name != NULL, NULL, error);
base_uri = rsvg_get_base_uri_from_filename (file_name);
data = _rsvg_io_acquire_data (file_name, base_uri, NULL, &data_len, error);
data = _rsvg_io_acquire_data (file_name, base_uri, NULL, &data_len, NULL, error);
if (data) {
handle = rsvg_handle_new ();
......
......@@ -1749,6 +1749,7 @@ rsvg_handle_read_stream_sync (RsvgHandle *handle,
int result;
xmlDocPtr doc;
GError *err = NULL;
gboolean res = FALSE;
g_return_val_if_fail (RSVG_IS_HANDLE (handle), FALSE);
g_return_val_if_fail (G_IS_INPUT_STREAM (stream), FALSE);
......@@ -1758,6 +1759,7 @@ rsvg_handle_read_stream_sync (RsvgHandle *handle,
priv = handle->priv;
priv->error = &err;
priv->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
if (priv->ctxt == NULL) {
priv->ctxt = xmlCreatePushParserCtxt (&rsvgSAXHandlerStruct, handle, NULL, 0,
rsvg_handle_get_base_uri (handle));
......@@ -1775,7 +1777,7 @@ rsvg_handle_read_stream_sync (RsvgHandle *handle,
if (xmlPushInput (priv->ctxt, input) < 0) {
rsvg_set_error (error, priv->ctxt);
xmlFreeInputStream (input);
return FALSE;
goto out;
}
result = xmlParseDocument (priv->ctxt);
......@@ -1785,14 +1787,12 @@ rsvg_handle_read_stream_sync (RsvgHandle *handle,
else
rsvg_set_error (error, handle->priv->ctxt);
return FALSE;
goto out;
}
priv->error = NULL;
if (err != NULL) {
g_propagate_error (error, err);
return FALSE;
goto out;
}
doc = priv->ctxt->myDoc;
......@@ -1804,7 +1804,14 @@ rsvg_handle_read_stream_sync (RsvgHandle *handle,
rsvg_defs_resolve_all (priv->defs);
priv->finished = TRUE;
return TRUE;
res = TRUE;
out:
priv->error = NULL;
g_clear_object (&priv->cancellable);
return res;
}
/**
......@@ -2153,7 +2160,12 @@ _rsvg_handle_acquire_data (RsvgHandle *handle,
if (!_rsvg_handle_allow_load (handle, uri, error))
return NULL;
return _rsvg_io_acquire_data (uri, rsvg_handle_get_base_uri (handle), content_type, len, error);
return _rsvg_io_acquire_data (uri,
rsvg_handle_get_base_uri (handle),
content_type,
len,
handle->priv->cancellable,
error);
}
GInputStream *
......@@ -2165,5 +2177,9 @@ _rsvg_handle_acquire_stream (RsvgHandle *handle,
if (!_rsvg_handle_allow_load (handle, uri, error))
return NULL;
return _rsvg_io_acquire_stream (uri, rsvg_handle_get_base_uri (handle), content_type, error);
return _rsvg_io_acquire_stream (uri,
rsvg_handle_get_base_uri (handle),
content_type,
handle->priv->cancellable,
error);
}
......@@ -127,7 +127,7 @@ rsvg_pixbuf_from_file_with_size_data (const gchar * file_name,
gsize data_len;
GString *base_uri = g_string_new (file_name);
data = _rsvg_io_acquire_data (file_name, base_uri->str, NULL, &data_len, error);
data = _rsvg_io_acquire_data (file_name, base_uri->str, NULL, &data_len, NULL, error);
if (data) {
pixbuf = rsvg_pixbuf_from_stdio_file_with_size_data (data, data_len,
......
......@@ -90,6 +90,7 @@ rsvg_handle_init (RsvgHandle * self)
self->priv->finished = 0;
self->priv->data_input_stream = NULL;
self->priv->first_write = TRUE;
self->priv->cancellable = NULL;
self->priv->is_disposed = FALSE;
self->priv->in_loop = FALSE;
......@@ -130,6 +131,8 @@ rsvg_handle_dispose (GObject *instance)
self->priv->data_input_stream = NULL;
}
g_clear_object (&self->priv->cancellable);
chain:
G_OBJECT_CLASS (rsvg_handle_parent_class)->dispose (instance);
}
......
......@@ -159,6 +159,7 @@ rsvg_acquire_file_data (const char *filename,
const char *base_uri,
char **out_content_type,
gsize *out_len,
GCancellable *cancellable,
GError **error)
{
GFile *file;
......@@ -193,6 +194,7 @@ static GInputStream *
rsvg_acquire_gvfs_stream (const char *uri,
const char *base_uri,
char **out_content_type,
GCancellable *cancellable,
GError **error)
{
GFile *base, *file;
......@@ -202,7 +204,7 @@ rsvg_acquire_gvfs_stream (const char *uri,
file = g_file_new_for_uri (uri);
stream = g_file_read (file, NULL /* cancellable */, &err);
stream = g_file_read (file, cancellable, &err);
g_object_unref (file);
if (stream == NULL &&
......@@ -213,7 +215,7 @@ rsvg_acquire_gvfs_stream (const char *uri,
file = g_file_resolve_relative_path (base, uri);
g_object_unref (base);
stream = g_file_read (file, NULL /* cancellable */, &err);
stream = g_file_read (file, cancellable, &err);
g_object_unref (file);
}
......@@ -227,7 +229,7 @@ rsvg_acquire_gvfs_stream (const char *uri,
file_info = g_file_input_stream_query_info (stream,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
NULL /* cancellable */,
cancellable,
NULL /* error */);
if (file_info) {
*out_content_type = g_strdup (g_file_info_get_content_type (file_info));
......@@ -237,7 +239,7 @@ rsvg_acquire_gvfs_stream (const char *uri,
}
}
return stream;
return G_INPUT_STREAM (stream);
}
static guint8 *
......@@ -245,6 +247,7 @@ rsvg_acquire_gvfs_data (const char *uri,
const char *base_uri,
char **out_content_type,
gsize *out_len,
GCancellable *cancellable,
GError **error)
{
GFile *base, *file;
......@@ -258,7 +261,7 @@ rsvg_acquire_gvfs_data (const char *uri,
err = NULL;
data = NULL;
if (!(res = g_file_load_contents (file, NULL, &data, &len, NULL, &err)) &&
if (!(res = g_file_load_contents (file, cancellable, &data, &len, NULL, &err)) &&
g_error_matches (err, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) &&
base_uri != NULL) {
g_clear_error (&err);
......@@ -267,7 +270,7 @@ rsvg_acquire_gvfs_data (const char *uri,
file = g_file_resolve_relative_path (base, uri);
g_object_unref (base);
res = g_file_load_contents (file, NULL, &data, &len, NULL, &err);
res = g_file_load_contents (file, cancellable, &data, &len, NULL, &err);
}
g_object_unref (file);
......@@ -290,6 +293,7 @@ _rsvg_io_acquire_data (const char *href,
const char *base_uri,
char **content_type,
gsize *len,
GCancellable *cancellable,
GError **error)
{
guint8 *data;
......@@ -307,10 +311,10 @@ _rsvg_io_acquire_data (const char *href,
if (strncmp (href, "data:", 5) == 0)
return rsvg_acquire_data_data (href, NULL, content_type, len, error);
if ((data = rsvg_acquire_file_data (href, base_uri, content_type, len, NULL)))
if ((data = rsvg_acquire_file_data (href, base_uri, content_type, len, cancellable, NULL)))
return data;
if ((data = rsvg_acquire_gvfs_data (href, base_uri, content_type, len, error)))
if ((data = rsvg_acquire_gvfs_data (href, base_uri, content_type, len, cancellable, error)))
return data;
return NULL;
......@@ -320,6 +324,7 @@ GInputStream *
_rsvg_io_acquire_stream (const char *href,
const char *base_uri,
char **content_type,
GCancellable *cancellable,
GError **error)
{
GInputStream *stream;
......@@ -339,10 +344,10 @@ _rsvg_io_acquire_stream (const char *href,
return g_memory_input_stream_new_from_data (data, len, (GDestroyNotify) g_free);
}
if ((data = rsvg_acquire_file_data (href, base_uri, content_type, &len, NULL)))
if ((data = rsvg_acquire_file_data (href, base_uri, content_type, &len, cancellable, NULL)))
return g_memory_input_stream_new_from_data (data, len, (GDestroyNotify) g_free);
if ((stream = rsvg_acquire_gvfs_stream (href, base_uri, content_type, error)))
if ((stream = rsvg_acquire_gvfs_stream (href, base_uri, content_type, cancellable, error)))
return stream;
return NULL;
......
......@@ -30,11 +30,13 @@ guint8* _rsvg_io_acquire_data (const char *uri,
const char *base_uri,
char **content_type,
gsize *len,
GCancellable *cancellable,
GError **error);
GInputStream *_rsvg_io_acquire_stream (const char *uri,
const char *base_uri,
char **content_type,
GCancellable *cancellable,
GError **error);
#endif /* RSVG_IO_H */
......@@ -161,6 +161,7 @@ struct RsvgHandlePrivate {
xmlParserCtxtPtr ctxt;
GError **error;
GCancellable *cancellable;
double dpi_x;
double dpi_y;
......
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