1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
|
/*
* Copyright © 2008-2009 Ryan Lortie
* Copyright © 2010 Codethink Limited
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the licence, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
* Author: Ryan Lortie <desrt@desrt.ca>
*/
#include "config.h"
#include "dconf-paths.h"
#include "dconf-enums.h"
/**
* SECTION:paths
* @title: dconf Paths
* @short_description: utility functions to validate dconf paths
*
* Various places in the dconf API speak of "paths", "keys", "dirs" and
* relative versions of each of these. This file contains functions to
* check if a given string is a valid member of each of these classes
* and to report errors when a string is not.
*
* See each function in this section for a precise description of what
* makes a string a valid member of a given class.
**/
#define vars gchar c, l
#define nonnull \
if (string == NULL) { \
g_set_error (error, DCONF_ERROR, DCONF_ERROR_PATH, \
"%s not specified", type); \
return FALSE; \
}
#define absolute \
if ((l = *string++) != '/') \
{ \
g_set_error (error, DCONF_ERROR, DCONF_ERROR_PATH, \
"dconf %s must begin with a slash", type); \
return FALSE; \
}
#define relative \
if (*string == '/') \
{ \
g_set_error (error, DCONF_ERROR, DCONF_ERROR_PATH, \
"dconf %s must not begin with a slash", type); \
return FALSE; \
} \
l = '/'
#define no_double_slash \
while ((c = *string++)) \
{ \
if (c == '/' && l == '/') \
{ \
g_set_error (error, DCONF_ERROR, DCONF_ERROR_PATH, \
"dconf %s must not contain two " \
"consecutive slashes", type); \
return FALSE; \
} \
l = c; \
} \
#define path \
return TRUE
#define key \
if (l == '/') \
{ \
g_set_error (error, DCONF_ERROR, DCONF_ERROR_PATH, \
"dconf %s must not end with a slash", type); \
return FALSE; \
} \
return TRUE
#define dir \
if (l != '/') \
{ \
g_set_error (error, DCONF_ERROR, DCONF_ERROR_PATH, \
"dconf %s must end with a slash", type); \
return FALSE; \
} \
return TRUE
/**
* dconf_is_path:
* @string: a string
* @error: a pointer to a #GError, or %NULL, set when %FALSE is returned
*
* Checks if @string is a valid dconf path. dconf keys must start with
* '/' and not contain '//'.
*
* A dconf path may be either a key or a dir. See dconf_is_key() and
* dconf_is_dir() for examples of each.
*
* Returns: %TRUE if @string is a path
**/
gboolean
dconf_is_path (const gchar *string,
GError **error)
{
#define type "path"
vars; nonnull; absolute; no_double_slash; path;
#undef type
}
/**
* dconf_is_key:
* @string: a string
* @error: a pointer to a #GError, or %NULL, set when %FALSE is returned
*
* Checks if @string is a valid dconf key. dconf keys must start with
* '/', not contain '//' and not end with '/'.
*
* A dconf key is the potential location of a single value within the
* database.
*
* "/a", "/a/b" and "/a/b/c" are examples of keys. "", "/", "a", "a/b",
* "//a/b", "/a//b", and "/a/" are examples of strings that are not
* keys.
*
* Returns: %TRUE if @string is a key
**/
gboolean
dconf_is_key (const gchar *string,
GError **error)
{
#define type "key"
vars; nonnull; absolute; no_double_slash; key;
#undef type
}
/**
* dconf_is_dir:
* @string: a string
* @error: a pointer to a #GError, or %NULL, set when %FALSE is returned
*
* Checks if @string is a valid dconf dir. dconf dirs must start and
* end with '/' and not contain '//'.
*
* A dconf dir refers to a subtree of the database that can contain
* other dirs or keys. If @string is a dir, then it will be a prefix of
* any key or dir contained within it.
*
* "/", "/a/" and "/a/b/" are examples of dirs. "", "a/", "a/b/",
* "//a/b/", "/a//b/" and "/a" are examples of strings that are not
* dirs.
*
* Returns: %TRUE if @string is a dir
**/
gboolean
dconf_is_dir (const gchar *string,
GError **error)
{
#define type "dir"
vars; nonnull; absolute; no_double_slash; dir;
#undef type
}
/**
* dconf_is_rel_path:
* @string: a string
* @error: a pointer to a #GError, or %NULL, set when %FALSE is returned
*
* Checks if @string is a valid dconf relative path. A relative path is
* a string that, when concatenated to a dir, forms a valid dconf path.
* This means that a rel must not start with a '/' or contain '//'.
*
* A dconf rel may be either a relative key or a relative dir. See
* dconf_is_rel_key() and dconf_is_rel_dir() for examples of each.
*
* Returns: %TRUE if @string is a relative path
**/
gboolean
dconf_is_rel_path (const gchar *string,
GError **error)
{
#define type "relative path"
vars; nonnull; relative; no_double_slash; path;
#undef type
}
/**
* dconf_is_rel_key:
* @string: a string
* @error: a pointer to a #GError, or %NULL, set when %FALSE is returned
*
* Checks if @string is a valid dconf relative key. A relative key is a
* string that, when concatenated to a dir, forms a valid dconf key.
* This means that a relative key must not start or end with a '/' or
* contain '//'.
*
* "a", "a/b" and "a/b/c" are examples of relative keys. "", "/", "/a",
* "/a/b", "//a/b", "/a//b", and "a/" are examples of strings that are
* not relative keys.
*
* Returns: %TRUE if @string is a relative key
**/
gboolean
dconf_is_rel_key (const gchar *string,
GError **error)
{
#define type "relative key"
vars; nonnull; relative; no_double_slash; key;
#undef type
}
/**
* dconf_is_rel_dir:
* @string: a string
* @error: a pointer to a #GError, or %NULL, set when %FALSE is returned
*
* Checks if @string is a valid dconf relative dir. A relative dir is a
* string that, when appended to a dir, forms a valid dconf dir. This
* means that a relative dir must not start with a '/' or contain '//'
* and must end with a '/' except in the case that it is the empty
* string (in which case the path specified by appending the rel to a
* directory is the original directory).
*
* "", "a/" and "a/b/" are examples of relative dirs. "/", "/a/",
* "/a/b/", "//a/b/", "a//b/" and "a" are examples of strings that are
* not relative dirs.
*
* Returns: %TRUE if @string is a relative dir
**/
gboolean
dconf_is_rel_dir (const gchar *string,
GError **error)
{
#define type "relative dir"
vars; nonnull; relative; no_double_slash; dir;
#undef type
}
|