From 86ee51b38aa335c156a350fcb2f4458c3f9871fa Mon Sep 17 00:00:00 2001 From: Dennis Tomas Date: Sat, 1 Sep 2007 15:26:23 +0200 Subject: [PATCH] Don't allow SetIcon/UnsetIcon SOAP calls to (un)set icons set by the user. --- ROX-Filer/src/remote.c | 4 +- ROX-Filer/src/usericons.c | 96 ++++++++++++++++++++++++++++++++++++++--------- ROX-Filer/src/usericons.h | 4 +- 3 files changed, 83 insertions(+), 21 deletions(-) diff --git a/ROX-Filer/src/remote.c b/ROX-Filer/src/remote.c index b71a06ac..07c116a4 100644 --- a/ROX-Filer/src/remote.c +++ b/ROX-Filer/src/remote.c @@ -640,7 +640,7 @@ static xmlNodePtr rpc_SetIcon(GList *args) path = string_value(ARG(0)); icon = string_value(ARG(1)); - add_globicon(path,icon); + add_globicon(path,icon,TRUE); g_free(path); g_free(icon); @@ -654,7 +654,7 @@ static xmlNodePtr rpc_UnsetIcon(GList *args) path = string_value(ARG(0)); - delete_globicon(path); + delete_globicon(path, TRUE); g_free(path); diff --git a/ROX-Filer/src/usericons.c b/ROX-Filer/src/usericons.c index 59b74926..bbe328fa 100644 --- a/ROX-Filer/src/usericons.c +++ b/ROX-Filer/src/usericons.c @@ -57,10 +57,18 @@ #define SET_PATH 0 /* Store in globicons */ #define SET_COPY 3 /* Create .DirIcon */ -static GHashTable *glob_icons = NULL; /* Pathname -> Icon pathname */ +static GHashTable *glob_icons = NULL; /* Pathname -> GlobIcon */ + +typedef struct _GlobIcon GlobIcon; +struct _GlobIcon { + gchar *path; + gboolean via_rpc; +}; /* Static prototypes */ static const char *process_globicons_line(gchar *line); +static GlobIcon *glob_icon_new(const gchar *path, gboolean via_rpc); +static void glob_icon_free(GlobIcon *icon); static gboolean free_globicon(gpointer key, gpointer value, gpointer data); static void write_globicons(void); static void drag_icon_dropped(GtkWidget *drop_box, @@ -103,13 +111,14 @@ void read_globicons() { xmlNodePtr node, icon, root; char *match; + GlobIcon *gi = NULL; root = xmlDocGetRootElement(doc); /* Handle the new XML file format */ for (node = root->xmlChildrenNode; node; node = node->next) { - gchar *path, *icon_path; + gchar *path, *via_rpc; if (node->type != XML_ELEMENT_NODE) continue; @@ -121,11 +130,15 @@ void read_globicons() match = xmlGetProp(node, "match"); if (!match) continue; + via_rpc = xmlGetProp(node, "set-by-app"); - icon_path = xmlNodeGetContent(icon); + gi = glob_icon_new(xmlNodeGetContent(icon), + via_rpc != NULL && text_to_boolean(via_rpc, FALSE)); path = expand_path(match); - g_hash_table_insert(glob_icons, path, icon_path); + g_hash_table_insert(glob_icons, path, gi); g_free(match); + if (via_rpc) + g_free(via_rpc); } xmlFreeDoc(doc); @@ -148,13 +161,13 @@ out: */ void check_globicon(const guchar *path, DirItem *item) { - gchar *gi; + GlobIcon *gi; g_return_if_fail(item && !item->_image); gi = g_hash_table_lookup(glob_icons, path); if (gi) - item->_image = g_fscache_lookup(pixmap_cache, gi); + item->_image = g_fscache_lookup(pixmap_cache, gi->path); } static gboolean create_diricon(const guchar *filepath, const guchar *iconpath) @@ -195,7 +208,7 @@ static gboolean set_icon_path(const guchar *filepath, const guchar *iconpath) g_object_unref(pic); /* Add the globicon mapping and update visible icons */ - add_globicon(filepath, iconpath); + add_globicon(filepath, iconpath, FALSE); return TRUE; } @@ -218,7 +231,7 @@ static void clear_icon(DropBox *drop_box, GObject *dialog) if (radios_get_value(radios) == SET_PATH) { - delete_globicon(pathname); + delete_globicon(pathname, FALSE); } else { @@ -341,6 +354,26 @@ void icon_set_handler_dialog(DirItem *item, const guchar *path) /**************************************************************** * INTERNAL FUNCTIONS * ****************************************************************/ + +static GlobIcon *glob_icon_new(const gchar *path, gboolean via_rpc) +{ + GlobIcon *icon; + + icon = g_new(GlobIcon, 1); + icon->path = g_strdup(path); + icon->via_rpc = via_rpc; + + return icon; +} + +static void glob_icon_free(GlobIcon *icon) +{ + g_return_if_fail(icon != NULL); + + g_free(icon->path); + g_free(icon); +} + /* The dropbox shows the path for the currently selected radio setting. */ @@ -389,9 +422,12 @@ static void radios_changed(Radios *radios, gpointer data) } case SET_PATH: { - const char *gi; + GlobIcon *gi; gi = g_hash_table_lookup(glob_icons, path); - drop_box_set_path(drop_box, gi); + if (gi) + drop_box_set_path(drop_box, gi->path); + else + drop_box_set_path(drop_box, NULL); break; } case SET_COPY: @@ -413,7 +449,7 @@ static void radios_changed(Radios *radios, gpointer data) static gboolean free_globicon(gpointer key, gpointer value, gpointer data) { g_free(key); - g_free(value); + glob_icon_free(value); return TRUE; /* For g_hash_table_foreach_remove() */ } @@ -422,10 +458,14 @@ static void write_globicon(gpointer key, gpointer value, gpointer data) { xmlNodePtr doc = (xmlNodePtr) data; xmlNodePtr tree; + GlobIcon *icon; + icon = (GlobIcon *)value; tree = xmlNewTextChild(doc, NULL, "rule", NULL); xmlSetProp(tree, "match", key); - xmlNewTextChild(tree, NULL, "icon", value); + if (icon->via_rpc) + xmlSetProp(tree, "set-by-app", "true"); + xmlNewTextChild(tree, NULL, "icon", icon->path); } /* Write globicons file */ @@ -469,6 +509,7 @@ static void write_globicons(void) static const char *process_globicons_line(gchar *line) { guchar *pattern, *iconpath; + GlobIcon *icon; pattern = strtok(line, " \t"); /* We ignore empty lines, but they are no cause for a message */ @@ -481,7 +522,8 @@ static const char *process_globicons_line(gchar *line) g_return_val_if_fail(iconpath != NULL, "Invalid line in globicons: no icon specified"); - g_hash_table_insert(glob_icons, g_strdup(pattern), g_strdup(iconpath)); + icon = glob_icon_new(iconpath, FALSE); + g_hash_table_insert(glob_icons, g_strdup(pattern), icon); return NULL; } @@ -491,9 +533,20 @@ static const char *process_globicons_line(gchar *line) * added to the top of the list (so that it takes precedence over * other entries). */ -void add_globicon(const gchar *path, const gchar *icon) +void add_globicon(const gchar *path, const gchar *icon_path, gboolean via_rpc) { - g_hash_table_insert(glob_icons, g_strdup(path), g_strdup(icon)); + GlobIcon *icon; + + if (via_rpc) + { + icon = g_hash_table_lookup(glob_icons, path); + if (icon && !icon->via_rpc) + return; + } + + icon = glob_icon_new(icon_path, via_rpc); + + g_hash_table_insert(glob_icons, g_strdup(path), icon); /* Rewrite the globicons file */ write_globicons(); @@ -503,17 +556,26 @@ void add_globicon(const gchar *path, const gchar *icon) } /* Remove the globicon for a certain path */ -void delete_globicon(const gchar *path) +void delete_globicon(const gchar *path, gboolean via_rpc) { gpointer key, value; + GlobIcon *icon; if (!g_hash_table_lookup_extended(glob_icons, path, &key, &value)) return; + icon = (GlobIcon *)value; + + if (!icon) + return; + + if (via_rpc && !icon->via_rpc) + return; + g_hash_table_remove(glob_icons, path); g_free(key); - g_free(value); + glob_icon_free(icon); write_globicons(); examine(path); diff --git a/ROX-Filer/src/usericons.h b/ROX-Filer/src/usericons.h index 69682876..4fff3930 100644 --- a/ROX-Filer/src/usericons.h +++ b/ROX-Filer/src/usericons.h @@ -12,7 +12,7 @@ void read_globicons(void); void check_globicon(const guchar *path, DirItem *item); void icon_set_handler_dialog(DirItem *item, const guchar *path); -void add_globicon(const gchar *path, const gchar *icon); -void delete_globicon(const gchar *path); +void add_globicon(const gchar *path, const gchar *icon_path, gboolean via_rpc); +void delete_globicon(const gchar *path, gboolean via_rpc); #endif -- 2.11.4.GIT