Author: kelnos
Date: 2008-04-26 20:59:54 +0000 (Sat, 26 Apr 2008)
New Revision: 26891

Modified:
   xfconf/trunk/common/xfconf-errors.c
   xfconf/trunk/xfconf/xfconf-errors.h
   xfconf/trunk/xfconfd/xfconf-backend.c
Log:
validate property names and throw an error if they're bad


Modified: xfconf/trunk/common/xfconf-errors.c
===================================================================
--- xfconf/trunk/common/xfconf-errors.c 2008-04-26 15:42:39 UTC (rev 26890)
+++ xfconf/trunk/common/xfconf-errors.c 2008-04-26 20:59:54 UTC (rev 26891)
@@ -34,6 +34,13 @@
 
 
 /**
+ * XFCONF_TYPE_ERROR:
+ *
+ * An enum GType for Xfconf errors.
+ **/
+
+
+/**
  * XfconfError:
  *
  * An enumeration listing the different kinds of errors under the
@@ -67,6 +74,7 @@
             { XFCONF_ERROR_PERMISSION_DENIED, 
"XFCONF_ERROR_PERMISSION_DENIED", "PermissionDenied" },
             { 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" },
             { 0, NULL, NULL }
         };
         

Modified: xfconf/trunk/xfconf/xfconf-errors.h
===================================================================
--- xfconf/trunk/xfconf/xfconf-errors.h 2008-04-26 15:42:39 UTC (rev 26890)
+++ xfconf/trunk/xfconf/xfconf-errors.h 2008-04-26 20:59:54 UTC (rev 26891)
@@ -41,6 +41,7 @@
     XFCONF_ERROR_PERMISSION_DENIED,
     XFCONF_ERROR_INTERNAL_ERROR,
     XFCONF_ERROR_NO_BACKEND,
+    XFCONF_ERROR_INVALID_PROPERTY,
 } XfconfError;
 
 GType xfconf_error_get_type() G_GNUC_CONST;

Modified: xfconf/trunk/xfconfd/xfconf-backend.c
===================================================================
--- xfconf/trunk/xfconfd/xfconf-backend.c       2008-04-26 15:42:39 UTC (rev 
26890)
+++ xfconf/trunk/xfconfd/xfconf-backend.c       2008-04-26 20:59:54 UTC (rev 
26891)
@@ -28,6 +28,8 @@
 
 static void xfconf_backend_base_init(gpointer g_class);
 
+static inline gboolean xfconf_property_is_valid(const gchar *property,
+                                                GError **error);
 
 /**
  * XfconfBackendInterface:
@@ -87,6 +89,50 @@
 
 
 
+static inline gboolean
+xfconf_property_is_valid(const gchar *property,
+                         GError **error)
+{
+    const gchar *p = property;
+
+    if(!p || *p != '/') {
+        if(error) {
+            g_set_error(error, XFCONF_ERROR, XFCONF_ERROR_INVALID_PROPERTY,
+                        _("Property names must start with a '/' character"));
+        }
+        return FALSE;
+    }
+
+    p++;
+    while(*p) {
+        if(!(*p >= 'A' && *p <= 'Z') && !(*p >= 'a' && *p <= 'z')
+           && *p != '_' && *p != '-' && *p != '/')
+        {
+            if(error) {
+                g_set_error(error, XFCONF_ERROR,
+                            XFCONF_ERROR_INVALID_PROPERTY,
+                            _("Property names can only include the ASCII 
characters A-Z, a-z, 0-9, '_', and '-', as well as '/' as a separator"));
+            }
+            return FALSE;
+        }
+
+        if('/' == *p && '/' == *(p-1)) {
+            if(error) {
+                g_set_error(error, XFCONF_ERROR,
+                            XFCONF_ERROR_INVALID_PROPERTY,
+                            _("Property names cannot have two or more '/' 
characters in a row"));
+            }
+            return FALSE;
+        }
+
+        p++;
+    }
+
+    return TRUE;
+}
+
+
+
 /**
  * xfconf_backend_initialize:
  * @backend: The #XfconfBackend.
@@ -136,6 +182,8 @@
     xfconf_backend_return_val_if_fail(iface && iface->set && channel && 
*channel
                                       && property && *property
                                       && value && (!error || !*error), FALSE);
+    if(!xfconf_property_is_valid(property, error))
+        return FALSE;
     
     return iface->set(backend, channel, property, value, error);
 }
@@ -166,6 +214,8 @@
     xfconf_backend_return_val_if_fail(iface && iface->get && channel && 
*channel
                                       && property && *property
                                       && value && (!error || !*error), FALSE);
+    if(!xfconf_property_is_valid(property, error))
+        return FALSE;
     
     return iface->get(backend, channel, property, value, error);
 }
@@ -196,7 +246,7 @@
     xfconf_backend_return_val_if_fail(iface && iface->get_all && channel
                                       && *channel && properties
                                       && (!error || !*error), FALSE);
-    
+ 
     return iface->get_all(backend, channel, properties, error);
 }
 
@@ -228,7 +278,9 @@
                                       && *channel && property && *property
                                       && exists
                                       && (!error || !*error), FALSE);
-    
+   if(!xfconf_property_is_valid(property, error))
+        return FALSE;
+ 
     return iface->exists(backend, channel, property, exists, error);
 }
 
@@ -256,6 +308,8 @@
     xfconf_backend_return_val_if_fail(iface && iface->remove && channel
                                       && *channel && property && *property
                                       && (!error || !*error), FALSE);
+    if(!xfconf_property_is_valid(property, error))
+        return FALSE;
     
     return iface->remove(backend, channel, property, error);
 }

_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to