Re: automatic method chaining the "right" way



> Well, we don't have to stat anything whose pathname does suggest a
> certain mime-type, in this case it would math *.tar and that mime-type
> information -- gained from only a string match, not a full stat yet --
> would give the has_directory_ops flag. Possibly an externally installed
> application handles this mime-type and has a gnome-vfs plugin for it,
> and has registered itself as such, or one of the gnome-vfs stock modules
> can handle it.  You can then stat that limited number of files to
> determine the real mime-type and proceed with that?

Attached is a small program that implements at least a start of
something that would do this.  It's missing some pieces and "proper"
behavior checks.  Mostly, it should cache (fulfilled) requests that
include explicit chaining as well as doing the checking on a per-method
(rather than whole-uri) basis. This is just the checks, not
implementation of the uri-rewriting.

--Shahms
#include <libgnomevfs/gnome-vfs.h>
#include <glib.h>
#include "gnome-vfs-mime.h"
#include <string.h>


static GHashTable *mime_cache;

int
main (int argc, char **argv)
{
  gboolean in_cache = FALSE;
  const char *mime_type;
  const char *real_mime;
  char sep = '/';
  char *uri = g_strdup (argv[1]);
  char *last = uri;

  mime_cache = g_hash_table_new (g_str_hash, g_str_equal);

  gnome_vfs_init();

  
  while ((last = strchr (last, sep)) != NULL) {
    *last = '\0';

    if ((mime_type = g_hash_table_lookup (mime_cache, last)) == NULL) {
	mime_type = gnome_vfs_mime_type_from_name(uri);
	in_cache = FALSE;
    } else
	in_cache = TRUE;

    if (strcmp (mime_type, "application/octet-stream")) {
      /* get GnomeVFSFileInfo and double check mime-type
       * if it is something that offers directory ops,
       * chain the appropriate methods 
       */

      if (!in_cache)
	g_hash_table_insert (mime_cache, 
			     g_strdup (last), g_strdup (mime_type));
      printf ("%s: %s\n", uri, mime_type);
    }

    *last = sep;
    ++last;
  }
  
  gnome_vfs_shutdown ();
  return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]