diff options
-rw-r--r-- | TODO | 5 | ||||
-rw-r--r-- | common/xfconf-errors.c | 1 | ||||
-rw-r--r-- | docs/reference/tmpl/xfconf-errors.sgml | 1 | ||||
-rw-r--r-- | xfconf/xfconf-errors.h | 1 | ||||
-rw-r--r-- | xfconfd/xfconf-backend.c | 51 |
5 files changed, 54 insertions, 5 deletions
@@ -1,6 +1,5 @@ -> for version 1.0 -* XfconfBackend needs to do better validation on channel and property names * unit tests - some done, need: - locking test - RemoveChannel() test @@ -22,7 +21,9 @@ changes? load it and send PropertyChanged for all properties? that could be very bad. * multi-screen support for xfsettingsd -* libxfce4mcs-client dummy implementation that forwards to libxfconf +* libxfce4mcs-client dummy implementation that forwards to libxfconf (?) +* maybe validate channel/prop names in libxfconf too to generate an error + without a roundtrip to the server (?) -> for future: diff --git a/common/xfconf-errors.c b/common/xfconf-errors.c index c388d37..7923a9c 100644 --- a/common/xfconf-errors.c +++ b/common/xfconf-errors.c @@ -75,6 +75,7 @@ xfconf_error_get_type() { XFCONF_ERROR_INTERNAL_ERROR, "XFCONF_ERROR_INTERNAL_ERROR", "InternalError" }, { XFCONF_ERROR_NO_BACKEND, "XFCONF_ERROR_NO_BACKEND", "NoBackend" }, { XFCONF_ERROR_INVALID_PROPERTY, "XFCONF_ERROR_INVALID_PROPERTY", "InvalidProperty" }, + { XFCONF_ERROR_INVALID_CHANNEL, "XFCONF_ERROR_INVALID_CHANNEL", "InvalidChannel" }, { 0, NULL, NULL } }; diff --git a/docs/reference/tmpl/xfconf-errors.sgml b/docs/reference/tmpl/xfconf-errors.sgml index 04cad31..cccf7a2 100644 --- a/docs/reference/tmpl/xfconf-errors.sgml +++ b/docs/reference/tmpl/xfconf-errors.sgml @@ -39,4 +39,5 @@ use of #GError<!-- -->s. @XFCONF_ERROR_INTERNAL_ERROR: An internal error (likely a bug in xfconf) occurred @XFCONF_ERROR_NO_BACKEND: No backends were found, or those found could not be loaded @XFCONF_ERROR_INVALID_PROPERTY: The property name specified was invalid +@XFCONF_ERROR_INVALID_CHANNEL: The channel name specified was invalid diff --git a/xfconf/xfconf-errors.h b/xfconf/xfconf-errors.h index ac1d2cb..b4f55a9 100644 --- a/xfconf/xfconf-errors.h +++ b/xfconf/xfconf-errors.h @@ -42,6 +42,7 @@ typedef enum XFCONF_ERROR_INTERNAL_ERROR, XFCONF_ERROR_NO_BACKEND, XFCONF_ERROR_INVALID_PROPERTY, + XFCONF_ERROR_INVALID_CHANNEL, } XfconfError; GType xfconf_error_get_type() G_GNUC_CONST; diff --git a/xfconfd/xfconf-backend.c b/xfconfd/xfconf-backend.c index a42679f..13edf91 100644 --- a/xfconfd/xfconf-backend.c +++ b/xfconfd/xfconf-backend.c @@ -30,6 +30,8 @@ static void xfconf_backend_base_init(gpointer g_class); static inline gboolean xfconf_property_is_valid(const gchar *property, GError **error); +static inline gboolean xfconf_channel_is_valid(const gchar *channel, + GError **error); /** * XfconfBackendInterface: @@ -131,6 +133,37 @@ xfconf_property_is_valid(const gchar *property, return TRUE; } +static inline gboolean +xfconf_channel_is_valid(const gchar *channel, + GError **error) +{ + const gchar *p = channel; + + if(!p || !*p) { + if(error) { + g_set_error(error, XFCONF_ERROR, XFCONF_ERROR_INVALID_CHANNEL, + _("Channel name cannot be an empty string")); + } + return FALSE; + } + + p++; + while(*p) { + if(!(*p >= 'A' && *p <= 'Z') && !(*p >= 'a' && *p <= 'z') + && *p != '_' && *p != '-') + { + if(error) { + g_set_error(error, XFCONF_ERROR, + XFCONF_ERROR_INVALID_CHANNEL, + _("Channel names can only include the ASCII characters A-Z, a-z, 0-9, '_', and '-'")); + } + return FALSE; + } + } + + return TRUE; +} + /** @@ -182,6 +215,8 @@ xfconf_backend_set(XfconfBackend *backend, xfconf_backend_return_val_if_fail(iface && iface->set && channel && *channel && property && *property && value && (!error || !*error), FALSE); + if(!xfconf_channel_is_valid(channel, error)) + return FALSE; if(!xfconf_property_is_valid(property, error)) return FALSE; @@ -214,6 +249,8 @@ xfconf_backend_get(XfconfBackend *backend, xfconf_backend_return_val_if_fail(iface && iface->get && channel && *channel && property && *property && value && (!error || !*error), FALSE); + if(!xfconf_channel_is_valid(channel, error)) + return FALSE; if(!xfconf_property_is_valid(property, error)) return FALSE; @@ -246,7 +283,9 @@ xfconf_backend_get_all(XfconfBackend *backend, xfconf_backend_return_val_if_fail(iface && iface->get_all && channel && *channel && properties && (!error || !*error), FALSE); - + if(!xfconf_channel_is_valid(channel, error)) + return FALSE; + return iface->get_all(backend, channel, properties, error); } @@ -278,7 +317,9 @@ xfconf_backend_exists(XfconfBackend *backend, && *channel && property && *property && exists && (!error || !*error), FALSE); - if(!xfconf_property_is_valid(property, error)) + if(!xfconf_channel_is_valid(channel, error)) + return FALSE; + if(!xfconf_property_is_valid(property, error)) return FALSE; return iface->exists(backend, channel, property, exists, error); @@ -308,6 +349,8 @@ xfconf_backend_remove(XfconfBackend *backend, xfconf_backend_return_val_if_fail(iface && iface->remove && channel && *channel && property && *property && (!error || !*error), FALSE); + if(!xfconf_channel_is_valid(channel, error)) + return FALSE; if(!xfconf_property_is_valid(property, error)) return FALSE; @@ -336,7 +379,9 @@ xfconf_backend_remove_channel(XfconfBackend *backend, xfconf_backend_return_val_if_fail(iface && iface->remove_channel && channel && *channel && (!error || !*error), FALSE); - + if(!xfconf_channel_is_valid(channel, error)) + return FALSE; + return iface->remove_channel(backend, channel, error); } |