[grilo-plugins/fremantle: 4/27] Added code to use GnomeVFS to get the whole content of a URL
- From: Xabier Rodriguez Calvar <xrcalvar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins/fremantle: 4/27] Added code to use GnomeVFS to get the whole content of a URL
- Date: Mon, 19 Apr 2010 16:48:46 +0000 (UTC)
commit 886d63a019c1710c568a9b8da5b5bf9e35480ea2
Author: Xabier Rodriguez Calvar <xrcalvar igalia com>
Date: Mon Apr 19 13:15:05 2010 +0200
Added code to use GnomeVFS to get the whole content of a URL
src/util/gnomevfs.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/util/gnomevfs.h | 36 +++++++++++++++
2 files changed, 154 insertions(+), 0 deletions(-)
---
diff --git a/src/util/gnomevfs.c b/src/util/gnomevfs.c
new file mode 100644
index 0000000..e7aac56
--- /dev/null
+++ b/src/util/gnomevfs.c
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2010 Igalia S.L.
+ *
+ * Contact: Iago Toral Quiroga <itoral igalia com>
+ *
+ * Authors: Xabier Rodriguez Calvar <xrcalvar igalia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gnomevfs.h>
+#include <libgnomevfs/gnome-vfs.h>
+#include <libgnomevfs/gnome-vfs-async-ops.h>
+#include <string.h>
+
+
+/* --------- Logging -------- */
+
+#undef G_LOG_DOMAIN
+#define G_LOG_DOMAIN "grl-util-gnomevfs"
+
+/* --- Misc --- */
+
+#define GNOME_VFS_READ_SIZE 4096
+
+typedef struct {
+ GString *contents;
+ GrlUtilGnomeVFSReadDoneCb read_done_cb;
+ gpointer read_done_user_data;
+} ReadCompleteInfo;
+
+static void
+gnome_vfs_close_cb (GnomeVFSAsyncHandle *handle, GnomeVFSResult result,
+ gpointer user_data)
+{
+ GrlUtilGnomeVFSReadDoneCb read_done_cb;
+ gpointer read_done_user_data;
+ gchar *contents;
+ ReadCompleteInfo *rci = user_data;
+
+ read_done_cb = rci->read_done_cb;
+ read_done_user_data = rci->read_done_user_data;
+
+ contents = g_string_free (rci->contents, result != GNOME_VFS_OK);
+
+ g_debug ("result ok? %s, contents: %s", result == GNOME_VFS_OK ? "yes" : "no", contents);
+
+ g_free (rci);
+
+ read_done_cb (contents, read_done_user_data);
+}
+
+static void
+gnome_vfs_read_cb (GnomeVFSAsyncHandle *handle, GnomeVFSResult result,
+ gpointer buffer, GnomeVFSFileSize bytes_requested,
+ GnomeVFSFileSize bytes_read, gpointer user_data)
+{
+ if (result == GNOME_VFS_OK || result == GNOME_VFS_ERROR_EOF) {
+ ReadCompleteInfo *rci = user_data;
+ g_string_append_len (rci->contents, buffer, bytes_read);
+ }
+
+ if (result == GNOME_VFS_OK) {
+ gnome_vfs_async_read (handle, buffer, GNOME_VFS_READ_SIZE,
+ gnome_vfs_read_cb, user_data);
+ } else {
+ g_free (buffer);
+ gnome_vfs_async_close (handle, gnome_vfs_close_cb, user_data);
+ }
+}
+
+static void
+gnome_vfs_open_cb (GnomeVFSAsyncHandle *handle, GnomeVFSResult result,
+ gpointer user_data)
+{
+ guchar *buffer = g_malloc (GNOME_VFS_READ_SIZE);
+
+ gnome_vfs_async_read (handle, buffer, GNOME_VFS_READ_SIZE,
+ gnome_vfs_read_cb, user_data);
+}
+
+void
+grl_plugins_gnome_vfs_read_url_async (const gchar *url,
+ GrlUtilGnomeVFSReadDoneCb cb,
+ gpointer user_data)
+{
+ GnomeVFSAsyncHandle *handle = NULL;
+ ReadCompleteInfo *rci;
+
+ rci = g_new (ReadCompleteInfo, 1);
+ rci->contents = g_string_sized_new (GNOME_VFS_READ_SIZE);
+ rci->read_done_cb = cb;
+ rci->read_done_user_data = user_data;
+
+ gnome_vfs_init ();
+
+ g_debug ("Opening '%s'", url);
+ gnome_vfs_async_open (&handle, url, GNOME_VFS_OPEN_READ,
+ GNOME_VFS_PRIORITY_DEFAULT, gnome_vfs_open_cb, rci);
+}
diff --git a/src/util/gnomevfs.h b/src/util/gnomevfs.h
new file mode 100644
index 0000000..4f50ea4
--- /dev/null
+++ b/src/util/gnomevfs.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2010 Igalia S.L.
+ *
+ * Contact: Iago Toral Quiroga <itoral igalia com>
+ *
+ * Authors: Xabier Rodriguez Calvar <xrcalvar igalia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; version 2.1 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef _GRL_GNOMEVFS_UTIL_H_
+#define _GRL_GNOMEVFS_UTIL_H_
+
+#include <glib.h>
+
+typedef void (*GrlUtilGnomeVFSReadDoneCb) (gchar *contents, gpointer user_data);
+
+void grl_plugins_gnome_vfs_read_url_async (const gchar *url,
+ GrlUtilGnomeVFSReadDoneCb cb,
+ gpointer user_data);
+
+#endif /* _GRL_GNOMEVFS_UTIL_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]