00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <config.h>
00026 #include "dbus-syntax.h"
00027
00028 #include "dbus-internals.h"
00029 #include "dbus-marshal-validate.h"
00030 #include "dbus-shared.h"
00031
00053 dbus_bool_t
00054 dbus_validate_path (const char *path,
00055 DBusError *error)
00056 {
00057 DBusString str;
00058 int len;
00059
00060 _dbus_return_val_if_fail (path != NULL, FALSE);
00061
00062 _dbus_string_init_const (&str, path);
00063 len = _dbus_string_get_length (&str);
00064
00065
00066 if (_DBUS_LIKELY (_dbus_validate_path (&str, 0, len)))
00067 return TRUE;
00068
00069
00070
00071 if (!_dbus_string_validate_utf8 (&str, 0, len))
00072 {
00073
00074
00075 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
00076 "Object path was not valid UTF-8");
00077 return FALSE;
00078 }
00079
00080
00081 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
00082 "Object path was not valid: '%s'", path);
00083 return FALSE;
00084 }
00085
00100 dbus_bool_t
00101 dbus_validate_interface (const char *name,
00102 DBusError *error)
00103 {
00104 DBusString str;
00105 int len;
00106
00107 _dbus_return_val_if_fail (name != NULL, FALSE);
00108
00109 _dbus_string_init_const (&str, name);
00110 len = _dbus_string_get_length (&str);
00111
00112
00113 if (_DBUS_LIKELY (_dbus_validate_interface (&str, 0, len)))
00114 return TRUE;
00115
00116
00117
00118 if (!_dbus_string_validate_utf8 (&str, 0, len))
00119 {
00120
00121
00122 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
00123 "Interface name was not valid UTF-8");
00124 return FALSE;
00125 }
00126
00127
00128 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
00129 "Interface name was not valid: '%s'", name);
00130 return FALSE;
00131 }
00132
00147 dbus_bool_t
00148 dbus_validate_member (const char *name,
00149 DBusError *error)
00150 {
00151 DBusString str;
00152 int len;
00153
00154 _dbus_return_val_if_fail (name != NULL, FALSE);
00155
00156 _dbus_string_init_const (&str, name);
00157 len = _dbus_string_get_length (&str);
00158
00159
00160 if (_DBUS_LIKELY (_dbus_validate_member (&str, 0, len)))
00161 return TRUE;
00162
00163
00164
00165 if (!_dbus_string_validate_utf8 (&str, 0, len))
00166 {
00167
00168
00169 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
00170 "Member name was not valid UTF-8");
00171 return FALSE;
00172 }
00173
00174
00175 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
00176 "Member name was not valid: '%s'", name);
00177 return FALSE;
00178 }
00179
00194 dbus_bool_t
00195 dbus_validate_error_name (const char *name,
00196 DBusError *error)
00197 {
00198 DBusString str;
00199 int len;
00200
00201 _dbus_return_val_if_fail (name != NULL, FALSE);
00202
00203 _dbus_string_init_const (&str, name);
00204 len = _dbus_string_get_length (&str);
00205
00206
00207 if (_DBUS_LIKELY (_dbus_validate_error_name (&str, 0, len)))
00208 return TRUE;
00209
00210
00211
00212 if (!_dbus_string_validate_utf8 (&str, 0, len))
00213 {
00214
00215
00216 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
00217 "Error name was not valid UTF-8");
00218 return FALSE;
00219 }
00220
00221
00222 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
00223 "Error name was not valid: '%s'", name);
00224 return FALSE;
00225 }
00226
00241 dbus_bool_t
00242 dbus_validate_bus_name (const char *name,
00243 DBusError *error)
00244 {
00245 DBusString str;
00246 int len;
00247
00248 _dbus_return_val_if_fail (name != NULL, FALSE);
00249
00250 _dbus_string_init_const (&str, name);
00251 len = _dbus_string_get_length (&str);
00252
00253
00254 if (_DBUS_LIKELY (_dbus_validate_bus_name (&str, 0, len)))
00255 return TRUE;
00256
00257
00258
00259 if (!_dbus_string_validate_utf8 (&str, 0, len))
00260 {
00261
00262
00263 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
00264 "Bus name was not valid UTF-8");
00265 return FALSE;
00266 }
00267
00268
00269 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
00270 "Bus name was not valid: '%s'", name);
00271 return FALSE;
00272 }
00273
00288 dbus_bool_t
00289 dbus_validate_utf8 (const char *alleged_utf8,
00290 DBusError *error)
00291 {
00292 DBusString str;
00293
00294 _dbus_return_val_if_fail (alleged_utf8 != NULL, FALSE);
00295
00296 _dbus_string_init_const (&str, alleged_utf8);
00297
00298 if (_DBUS_LIKELY (_dbus_string_validate_utf8 (&str, 0,
00299 _dbus_string_get_length (&str))))
00300 return TRUE;
00301
00302
00303
00304 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
00305 "String was not valid UTF-8");
00306 return FALSE;
00307 }
00308