Author: kelnos
Date: 2008-04-28 01:29:44 +0000 (Mon, 28 Apr 2008)
New Revision: 26898
Modified:
xfconf/trunk/TODO
xfconf/trunk/common/xfconf-errors.c
xfconf/trunk/docs/reference/tmpl/xfconf-errors.sgml
xfconf/trunk/xfconf/xfconf-errors.h
xfconf/trunk/xfconfd/xfconf-backend.c
Log:
validate channel names
Modified: xfconf/trunk/TODO
===================================================================
--- xfconf/trunk/TODO 2008-04-28 01:29:25 UTC (rev 26897)
+++ xfconf/trunk/TODO 2008-04-28 01:29:44 UTC (rev 26898)
@@ -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:
Modified: xfconf/trunk/common/xfconf-errors.c
===================================================================
--- xfconf/trunk/common/xfconf-errors.c 2008-04-28 01:29:25 UTC (rev 26897)
+++ xfconf/trunk/common/xfconf-errors.c 2008-04-28 01:29:44 UTC (rev 26898)
@@ -75,6 +75,7 @@
{ 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 }
};
Modified: xfconf/trunk/docs/reference/tmpl/xfconf-errors.sgml
===================================================================
--- xfconf/trunk/docs/reference/tmpl/xfconf-errors.sgml 2008-04-28 01:29:25 UTC
(rev 26897)
+++ xfconf/trunk/docs/reference/tmpl/xfconf-errors.sgml 2008-04-28 01:29:44 UTC
(rev 26898)
@@ -39,4 +39,5 @@
@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
[EMAIL PROTECTED]: The channel name specified was invalid
Modified: xfconf/trunk/xfconf/xfconf-errors.h
===================================================================
--- xfconf/trunk/xfconf/xfconf-errors.h 2008-04-28 01:29:25 UTC (rev 26897)
+++ xfconf/trunk/xfconf/xfconf-errors.h 2008-04-28 01:29:44 UTC (rev 26898)
@@ -42,6 +42,7 @@
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;
Modified: xfconf/trunk/xfconfd/xfconf-backend.c
===================================================================
--- xfconf/trunk/xfconfd/xfconf-backend.c 2008-04-28 01:29:25 UTC (rev
26897)
+++ xfconf/trunk/xfconfd/xfconf-backend.c 2008-04-28 01:29:44 UTC (rev
26898)
@@ -30,6 +30,8 @@
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,8 +133,39 @@
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;
+}
+
+
+
/**
* xfconf_backend_initialize:
* @backend: The #XfconfBackend.
@@ -182,6 +215,8 @@
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_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_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,8 +317,10 @@
&& *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_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_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);
}
_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits