aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ephy-file-helpers.c
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2005-01-01 00:09:40 +0800
committerChristian Persch <chpe@src.gnome.org>2005-01-01 00:09:40 +0800
commit9b8959a4de1dc5eacdf807ae6d311defce4fad51 (patch)
tree88ac3f23c1b1024b3b6d7101bbc6712ebd943e74 /lib/ephy-file-helpers.c
parentddf12994065314b103f57969640845d7344974f2 (diff)
downloadgsoc2013-epiphany-9b8959a4de1dc5eacdf807ae6d311defce4fad51.tar
gsoc2013-epiphany-9b8959a4de1dc5eacdf807ae6d311defce4fad51.tar.gz
gsoc2013-epiphany-9b8959a4de1dc5eacdf807ae6d311defce4fad51.tar.bz2
gsoc2013-epiphany-9b8959a4de1dc5eacdf807ae6d311defce4fad51.tar.lz
gsoc2013-epiphany-9b8959a4de1dc5eacdf807ae6d311defce4fad51.tar.xz
gsoc2013-epiphany-9b8959a4de1dc5eacdf807ae6d311defce4fad51.tar.zst
gsoc2013-epiphany-9b8959a4de1dc5eacdf807ae6d311defce4fad51.zip
Move mime permission checks to ephy-file-helpers.
2004-12-31 Christian Persch <chpe@cvs.gnome.org> * embed/ephy-embed-shell.c: (ephy_embed_shell_finalize), (ephy_embed_shell_get_encodings): * embed/ephy-embed-shell.h: * embed/mozilla/ContentHandler.cpp: * embed/mozilla/ContentHandler.h: * lib/ephy-file-helpers.c: (ephy_file_helpers_shutdown), (ephy_file_delete_on_exit), (load_mime_from_xml), (ephy_file_check_mime): * lib/ephy-file-helpers.h: Move mime permission checks to ephy-file-helpers. * src/popup-commands.c: (image_open_uri), (save_source_completed_cb), (popup_cmd_open_image): Only open the image if its mime type is 'safe'.
Diffstat (limited to 'lib/ephy-file-helpers.c')
-rw-r--r--lib/ephy-file-helpers.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index fb6e3ac1f..bc11f8e27 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2002 Jorn Baayen
+ * Copyright (C) 2003, 2004 Marco Pesenti Gritti
+ * Copyright (C) 2004 Christian Persch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -27,12 +29,15 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <libgnome/gnome-init.h>
+#include <libxml/xmlreader.h>
#include "ephy-file-helpers.h"
#include "ephy-prefs.h"
#include "eel-gconf-extensions.h"
+#include "ephy-debug.h"
static GHashTable *files = NULL;
+static GHashTable *mime_table = NULL;
static char *dot_dir = NULL;
static char *tmp_dir = NULL;
@@ -222,6 +227,13 @@ ephy_file_helpers_shutdown (void)
g_list_free (del_on_exit);
del_on_exit = NULL;
+ if (mime_table != NULL)
+ {
+ LOG ("Destroying mime type hashtable")
+ g_hash_table_destroy (mime_table);
+ mime_table = NULL;
+ }
+
if (tmp_dir != NULL)
{
rmdir (tmp_dir);
@@ -349,3 +361,88 @@ ephy_file_delete_on_exit (const char *path)
del_on_exit = g_list_prepend (del_on_exit,
g_strdup (path));
}
+
+static void
+load_mime_from_xml (void)
+{
+ xmlTextReaderPtr reader;
+ const char *xml_file;
+ int ret;
+ EphyMimePermission permission = EPHY_MIME_PERMISSION_UNKNOWN;
+
+ g_return_if_fail (mime_table == NULL);
+
+ mime_table = g_hash_table_new_full (g_str_hash, g_str_equal,
+ xmlFree, NULL);
+
+ xml_file = ephy_file ("mime-types-permissions.xml");
+ if (xml_file == NULL)
+ {
+ g_warning ("MIME types permissions file not found!\n");
+ return;
+ }
+
+ reader = xmlNewTextReaderFilename (xml_file);
+ if (reader == NULL)
+ {
+ g_warning ("Could not load MIME types permissions file!\n");
+ return;
+ }
+
+ ret = xmlTextReaderRead (reader);
+ while (ret == 1)
+ {
+ const xmlChar *tag;
+ xmlReaderTypes type;
+
+ tag = xmlTextReaderConstName (reader);
+ type = xmlTextReaderNodeType (reader);
+
+ if (xmlStrEqual (tag, "safe") && type == XML_READER_TYPE_ELEMENT)
+ {
+ permission = EPHY_MIME_PERMISSION_SAFE;
+ }
+ else if (xmlStrEqual (tag, "unsafe") && type == XML_READER_TYPE_ELEMENT)
+ {
+ permission = EPHY_MIME_PERMISSION_UNSAFE;
+ }
+ else if (xmlStrEqual (tag, "mime-type"))
+ {
+ xmlChar *type;
+
+ type = xmlTextReaderGetAttribute (reader, "type");
+ g_hash_table_insert (mime_table, type,
+ GINT_TO_POINTER (permission));
+ }
+
+ ret = xmlTextReaderRead (reader);
+ }
+
+ xmlFreeTextReader (reader);
+}
+
+EphyMimePermission
+ephy_file_check_mime (const char *mime_type)
+{
+ EphyMimePermission permission;
+ gpointer tmp;
+
+ g_return_val_if_fail (mime_type != NULL, EPHY_MIME_PERMISSION_UNKNOWN);
+
+ if (mime_table == NULL)
+ {
+ load_mime_from_xml ();
+ }
+
+ tmp = g_hash_table_lookup (mime_table, mime_type);
+ if (tmp == NULL)
+ {
+ permission = EPHY_MIME_PERMISSION_UNKNOWN;
+ }
+ else
+ {
+ permission = GPOINTER_TO_INT (tmp);
+ }
+
+ return permission;
+}