[libgsf] Always make a local copy of data in GsfInputHTTP. [see #724970]
- From: Jean Bréfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgsf] Always make a local copy of data in GsfInputHTTP. [see #724970]
- Date: Thu, 6 Mar 2014 13:26:28 +0000 (UTC)
commit c9e59c6439564d48a71bb659eda64bfd7844f1e0
Author: Jean Brefort <jean brefort normalesup org>
Date: Thu Mar 6 14:25:12 2014 +0100
Always make a local copy of data in GsfInputHTTP. [see #724970]
ChangeLog | 6 +++++
gsf/gsf-input-http.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 56 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4dffadf..d0c83d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-03-06 Jean Brefort <jean brefort normalesup org>
+
+ * gsf/gsf-input-http.c (make_local_copy), (gsf_input_http_new):
+ make a local copy. nanohttp does not always report the correct size.
+ [see #724970]
+
2014-03-05 Morten Welinder <terra gnome org>
* gsf/gsf-input-gio.c (gsf_input_gio_new): Always make local copy.
diff --git a/gsf/gsf-input-http.c b/gsf/gsf-input-http.c
index c1068b6..4b59e9e 100644
--- a/gsf/gsf-input-http.c
+++ b/gsf/gsf-input-http.c
@@ -215,6 +215,46 @@ gsf_input_http_get_content_type (GsfInputHTTP *input)
return content_type;
}
+static GsfInput *
+make_local_copy (gpointer *ctx)
+{
+ GsfOutput *out;
+ GsfInput *copy;
+
+ out = gsf_output_memory_new ();
+
+ while (1) {
+ guint8 buf[4096];
+ gssize nread;
+
+ nread = xmlNanoHTTPRead (ctx, buf, sizeof(buf));
+
+ if (nread > 0) {
+ if (!gsf_output_write (out, nread, buf)) {
+ copy = NULL;
+ goto cleanup_and_exit;
+ }
+ }
+ else if (nread == 0)
+ break;
+ else {
+ copy = NULL;
+ goto cleanup_and_exit;
+ }
+ }
+
+ copy = gsf_input_memory_new_clone
+ (gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (out)),
+ gsf_output_size (out));
+
+ cleanup_and_exit:
+
+ gsf_output_close (out);
+ g_object_unref (out);
+
+ return copy;
+}
+
/**
* gsf_input_http_new:
* @url: A string containing the URL to retrieve
@@ -226,6 +266,7 @@ GsfInput *
gsf_input_http_new (gchar const * url, GError **error G_GNUC_UNUSED)
{
GObject *obj;
+ GsfInput *input;
gpointer ctx;
char *content_type;
@@ -235,7 +276,15 @@ gsf_input_http_new (gchar const * url, GError **error G_GNUC_UNUSED)
if (!ctx) /* no meaningful errors provided by nanohttp */
return NULL;
- obj = g_object_new (GSF_INPUT_HTTP_TYPE,
+ /* always make a local copy
+ see https://bugzilla.gnome.org/show_bug.cgi?id=724970 */
+ input = make_local_copy (ctx);
+ if (input) {
+ gsf_input_set_name (input, url);
+ return input;
+ }
+
+ obj = g_object_new (GSF_INPUT_HTTP_TYPE,
"url", url,
"content-type", content_type,
NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]