summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorRobey Pointer <robey@src.gnome.org>2001-01-19 01:10:48 +0000
committerRobey Pointer <robey@src.gnome.org>2001-01-19 01:10:48 +0000
commit49a9a552c9aa67b58f9b4d7628515276c3e4b056 (patch)
tree86b4021da6d96058927fb0479ac7562c50642386 /components
parent9d17a2dd51451793ff39c8b1ad5aab585c27593b (diff)
downloadnautilus-49a9a552c9aa67b58f9b4d7628515276c3e4b056.tar.gz
Change the bootstrap installer download function to use the new gnome-http
* components/services/install/lib/eazel-install-object.c: * components/services/install/lib/eazel-install-protocols.c: (http_fetch_remote_file): * nautilus-installer/src/HACKING: Change the bootstrap installer download function to use the new gnome-http call to avoid buffering 8MB of package files in memory at once. * components/services/trilobite/libtrilobite/trilobite-core-network -slim.c: (trilobite_xml_get_string), (trilobite_fetch_uri), (trilobite_fetch_uri_to_file): Forgot to add this once -- needed by the bootstrap installer.
Diffstat (limited to 'components')
-rw-r--r--components/services/install/lib/eazel-install-object.c15
-rw-r--r--components/services/install/lib/eazel-install-protocols.c25
-rw-r--r--components/services/trilobite/libtrilobite/trilobite-core-network-slim.c175
3 files changed, 213 insertions, 2 deletions
diff --git a/components/services/install/lib/eazel-install-object.c b/components/services/install/lib/eazel-install-object.c
index e95ce078f..c4a769d87 100644
--- a/components/services/install/lib/eazel-install-object.c
+++ b/components/services/install/lib/eazel-install-object.c
@@ -1600,7 +1600,20 @@ eazel_install_emit_done_default (EazelInstall *service, gboolean result)
/* Welcome to define madness. These are all the get/set methods. There is nothing of
- interest beyond this point, except for a fucking big dragon*/
+ * interest beyond this point, except for this dragon:
+ _ _
+ _ //` `\
+ _,-"\% // /``\`\
+ ~^~ >__^ |% // / } `\`\
+ ) )%// / } } }`\`\
+ / (%/'/.\_/\_/\_/\`/
+ ( ' `-._`
+ \ , ( \ _`-.__.-;%>
+ /_`\ \ `\ \." `-..-'`
+ ``` /_/`"-=-'`/_/
+ jgs ``` ```
+*/
+
static void
string_list_copy (GList **in,
diff --git a/components/services/install/lib/eazel-install-protocols.c b/components/services/install/lib/eazel-install-protocols.c
index 37cf21f19..b5362be94 100644
--- a/components/services/install/lib/eazel-install-protocols.c
+++ b/components/services/install/lib/eazel-install-protocols.c
@@ -98,7 +98,8 @@ http_fetch_remote_file (EazelInstall *service,
ghttp_status status;
char* body;
FILE* file;
- int total_bytes=0;
+ int total_bytes = 0;
+ int last_flush_bytes = 0;
gboolean first_emit;
const char *report;
char *target_file_premove;
@@ -168,6 +169,28 @@ http_fetch_remote_file (EazelInstall *service,
curStat.bytes_read,
curStat.bytes_total);
}
+
+ /* arbitrary -- flush every 16k or so */
+ if (curStat.bytes_read > last_flush_bytes + 16384) {
+ ghttp_flush_response_buffer (request);
+ length = ghttp_get_body_len (request);
+ body = ghttp_get_body (request);
+ if (body != NULL) {
+ if (fwrite (body, length, 1, file) < 1) {
+ /* probably out of disk space */
+ g_warning (_("DISK FULL: could not write %s"), target_file);
+ service->private->disk_full = TRUE;
+ get_failed = 1;
+ break;
+ }
+ } else {
+ g_warning (_("Could not get request body!"));
+ get_failed = 1;
+ break;
+ }
+ last_flush_bytes = curStat.bytes_read;
+ }
+
g_main_iteration (FALSE);
}
/* Last emit amount==total */
diff --git a/components/services/trilobite/libtrilobite/trilobite-core-network-slim.c b/components/services/trilobite/libtrilobite/trilobite-core-network-slim.c
new file mode 100644
index 000000000..ba5531023
--- /dev/null
+++ b/components/services/trilobite/libtrilobite/trilobite-core-network-slim.c
@@ -0,0 +1,175 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * trilobite-core-network: functions for retrieving files from the
+ * network and parsing XML documents
+ * (this version is for the bootstrap installer, it's "slimmed down")
+ *
+ * Copyright (C) 2000 Eazel, Inc
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * Authors: J Shane Culpepper <pepper@eazel.com>
+ * Robey Pointer <robey@eazel.com>
+ * Eskil Heyn Olsen <eskil@eazel.com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <ghttp.h>
+#include <gnome.h>
+#include "trilobite-core-utils.h"
+#include "trilobite-core-network.h"
+
+
+/* function for lazy bastards who can't be bothered to figure out the format of the xml they're parsing:
+ * it checks for a property with the name, and then if there isn't one, then it tries to find a child
+ * with that name instead.
+ */
+char *
+trilobite_xml_get_string (xmlNode *node, const char *name)
+{
+ char *ret;
+ char *tmp;
+ xmlNode *child;
+
+ ret = xmlGetProp (node, name);
+ if (ret) {
+ goto good;
+ }
+ child = node->xmlChildrenNode;
+ while (child) {
+ if (g_strcasecmp (child->name, name) == 0) {
+ ret = xmlNodeGetContent (child);
+ if (ret) {
+ goto good;
+ }
+ }
+ child = child->next;
+ }
+ return NULL;
+
+good:
+ tmp = g_strdup (ret);
+ xmlFree (ret);
+ return tmp;
+}
+
+gboolean
+trilobite_fetch_uri (const char *uri_text, char **body, int *length)
+{
+ char *uri = NULL;
+ ghttp_request* request;
+ ghttp_status status;
+ gboolean result = TRUE;
+
+ g_assert (body!=NULL);
+ g_assert (uri_text != NULL);
+ g_assert (length != NULL);
+
+ uri = g_strdup (uri_text);
+ request = NULL;
+ (*length) = -1;
+ (*body) = NULL;
+
+ if ((request = ghttp_request_new())==NULL) {
+ g_warning (_("Could not create an http request !"));
+ result = FALSE;
+ }
+
+ /* bootstrap installer does it this way */
+ if (result && (g_getenv ("http_proxy") != NULL)) {
+ if (ghttp_set_proxy (request, g_getenv ("http_proxy")) != 0) {
+ g_warning (_("Proxy: Invalid uri !"));
+ result = FALSE;
+ }
+ }
+
+ if (result && (ghttp_set_uri (request, uri) != 0)) {
+ g_warning (_("Invalid uri !"));
+ result = FALSE;
+ }
+
+ if (result) {
+ ghttp_set_header (request, http_hdr_Connection, "close");
+ ghttp_set_header (request, http_hdr_User_Agent, trilobite_get_useragent_string (FALSE, NULL));
+ }
+
+ if (result && (ghttp_prepare (request) != 0)) {
+ g_warning (_("Could not prepare http request !"));
+ result = FALSE;
+ }
+
+ if (result && ghttp_set_sync (request, ghttp_async)) {
+ g_warning (_("Couldn't get async mode "));
+ result = FALSE;
+ }
+
+ while (result && (status = ghttp_process (request)) == ghttp_not_done) {
+ /* ghttp_current_status curStat = ghttp_get_status (request); */
+ g_main_iteration (FALSE);
+ }
+
+ if (result && (ghttp_status_code (request) != 200)) {
+ g_warning (_("HTTP error %d \"%s\" on uri %s"),
+ ghttp_status_code (request),
+ ghttp_reason_phrase (request),
+ uri);
+ result = FALSE;
+ }
+ if (result && (ghttp_status_code (request) != 404)) {
+ (*length) = ghttp_get_body_len (request);
+ (*body) = g_new0 (char, *length + 1);
+ memcpy (*body, ghttp_get_body (request), *length);
+ (*body)[*length] = 0;
+ } else {
+ result = FALSE;
+ }
+
+ if (request) {
+ ghttp_request_destroy (request);
+ }
+
+ g_free (uri);
+
+ return result;
+}
+
+gboolean
+trilobite_fetch_uri_to_file (const char *uri_text, const char *filename)
+{
+ char *body = NULL;
+ int length;
+ gboolean result = FALSE;
+
+ result = trilobite_fetch_uri (uri_text, &body, &length);
+ if (result) {
+ FILE* file;
+ file = fopen (filename, "wb");
+ if (file == NULL) {
+ g_warning (_("Could not open target file %s"),filename);
+ result = FALSE;
+ } else {
+ fwrite (body, length, 1, file);
+ }
+ fclose (file);
+ }
+
+ return result;
+}