Re: taking a stab at this
- From: "Shahms E. King" <shahms shahms com>
- To: gnome-vfs-list gnome org
- Subject: Re: taking a stab at this
- Date: 19 Sep 2002 01:26:21 -0700
*sigh* I new that would happen. This time the patch it attached.
And I managed to test it and it works with zip files ;-)
--Shahms
Index: libgnomevfs/gnome-vfs-uri.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-uri.c,v
retrieving revision 1.107
diff -u -r1.107 gnome-vfs-uri.c
--- libgnomevfs/gnome-vfs-uri.c 2002/07/15 09:01:52 1.107
+++ libgnomevfs/gnome-vfs-uri.c 2002/09/19 08:15:28
@@ -30,6 +30,8 @@
#include "gnome-vfs-private-utils.h"
#include "gnome-vfs-transform.h"
#include "gnome-vfs-utils.h"
+#include "gnome-vfs-mime.h"
+#include "gnome-vfs-mime-utils.h"
#include <glib/ghash.h>
#include <glib/gmessages.h>
#include <glib/gstrfuncs.h>
@@ -106,6 +108,8 @@
#define BV_SET(bv, idx) (bv)[((guchar)(idx))>>3] |= (1 << ( (idx) & 7) )
#define BV_IS_SET(bv, idx) ((bv)[(idx)>>3] & (1 << ( (idx) & 7)))
+#define USE_MIME_EXPANSION FALSE
+
static const char *
uri_strspn_to(const char *str, UriStrspnSet *set, const char *path_end)
{
@@ -301,17 +305,120 @@
return ret;
}
+/* forward declaration for uri_mime_parse */
+static GnomeVFSURI* set_uri_element (GnomeVFSURI *uri,
+ const gchar *text,
+ guint len,
+ gboolean mime_expand);
+
+static const gchar**
+get_mime_type_methods (const char* mime_type, gint *n_methods)
+{
+ static const gchar *tbz_methods[2] = {"bzip2", "tar"};
+ static const gchar *tgz_methods[2] = {"gzip", "tar"};
+ static const gchar *zip_methods[1] = {"zip"};
+ static const gchar *tar_methods[1] = {"tar"};
+
+ if (!strcmp (mime_type, "application/x-compressed-tar")) {
+ *n_methods = 2;
+ return tgz_methods;
+ }
+
+ if (!strcmp (mime_type, "application/x-bzip-compressed-tar")) {
+ *n_methods = 2;
+ return tbz_methods;
+ }
+
+ if (!strcmp (mime_type, "application/zip")) {
+ *n_methods = 1;
+ return zip_methods;
+ }
+
+ if (!strcmp (mime_type, "application/x-tar")) {
+ *n_methods = 1;
+ return tar_methods;
+ }
+
+ *n_methods = 0;
+ return NULL;
+}
+
+static GnomeVFSURI*
+uri_mime_parse (GnomeVFSURI *uri)
+{
+ GnomeVFSURI *last, *new_uri, *tmp_uri;
+ char *path_scanner;
+ char *curr_path, *tmp;
+ const char **methods;
+ const char *mime_type;
+ int n_methods, i;
+
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ if (uri->text == NULL)
+ return uri;
+
-static void
+ curr_path = g_strdup (uri->text);
+ path_scanner = curr_path;
+ while ((path_scanner = strchr (path_scanner, GNOME_VFS_URI_PATH_CHR)) != NULL) {
+ *path_scanner = '\0';
+
+ mime_type = gnome_vfs_mime_type_from_name (curr_path);
+ if (strcmp (mime_type, GNOME_VFS_MIME_TYPE_UNKNOWN)) {
+ methods = get_mime_type_methods (mime_type, &n_methods);
+ if (methods != NULL) {
+ tmp = uri->text;
+ set_uri_element (uri, curr_path,
+ path_scanner - curr_path, FALSE);
+ last = uri;
+ for (i = 0; i < n_methods; ++i) {
+ new_uri = g_new0 (GnomeVFSURI, 1);
+ set_uri_element (new_uri, NULL, 0, FALSE);
+ new_uri->parent = last;
+ new_uri->ref_count = 1;
+ new_uri->method_string = g_strdup (methods[i]);
+ new_uri->method = gnome_vfs_method_get (new_uri->method_string);
+ last = new_uri;
+ if (new_uri->method == NULL) {
+ g_free (uri->text);
+ uri->text = tmp;
+ while (last != uri) {
+ g_free (last->text);
+ g_free (last->method_string);
+ tmp_uri = last->parent;
+ gnome_vfs_uri_unref (last);
+ last = tmp_uri;
+ }
+ goto end;
+ }
+ }
+ g_free (last->text);
+ uri = set_uri_element (last, path_scanner,
+ strlen (path_scanner), TRUE);
+ g_free (tmp);
+ goto end;
+ }
+ }
+ *path_scanner = GNOME_VFS_URI_PATH_CHR;
+ ++path_scanner;
+ }
+ end:
+ g_free (curr_path);
+ return uri;
+}
+
+static GnomeVFSURI*
set_uri_element (GnomeVFSURI *uri,
const gchar *text,
- guint len)
+ guint len,
+ gboolean mime_expand)
{
char *escaped_text;
if (text == NULL || len == 0) {
uri->text = g_strdup("/");;
- return;
+ return uri;
}
if (uri->parent == NULL && text[0] == '/' && text[1] == '/') {
@@ -349,6 +456,11 @@
gnome_vfs_remove_optional_escapes (uri->text);
gnome_vfs_canonicalize_pathname (uri->text);
+
+ if (mime_expand)
+ uri = uri_mime_parse (uri);
+
+ return uri;
}
static const gchar *
@@ -405,12 +517,14 @@
extension_scanner = strchr (method_scanner, GNOME_VFS_URI_MAGIC_CHR);
if (extension_scanner == NULL) {
- set_uri_element (uri, method_scanner, strlen (method_scanner));
+ uri = set_uri_element (uri, method_scanner, strlen (method_scanner),
+ USE_MIME_EXPANSION);
return uri;
}
/* handle '#' */
- set_uri_element (uri, method_scanner, extension_scanner - method_scanner);
+ uri = set_uri_element (uri, method_scanner, extension_scanner - method_scanner,
+ USE_MIME_EXPANSION);
if (strchr (extension_scanner, ':') == NULL) {
/* extension is a fragment identifier */
@@ -509,13 +623,15 @@
extension_scanner = strchr (method_scanner, GNOME_VFS_URI_MAGIC_CHR);
if (extension_scanner == NULL) {
- set_uri_element (uri, method_scanner, strlen (method_scanner));
+ uri = set_uri_element (uri, method_scanner, strlen (method_scanner),
+ USE_MIME_EXPANSION);
g_free (new_uri_string);
return uri;
}
/* handle '#' */
- set_uri_element (uri, method_scanner, extension_scanner - method_scanner);
+ uri = set_uri_element (uri, method_scanner, extension_scanner - method_scanner,
+ USE_MIME_EXPANSION);
if (strchr (extension_scanner, ':') == NULL) {
/* extension is a fragment identifier */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]