dbus-marshal-validate.h

00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
00002 /* dbus-marshal-validate.h  Validation routines for marshaled data
00003  *
00004  * Copyright (C) 2005  Red Hat, Inc.
00005  *
00006  * Licensed under the Academic Free License version 2.1
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00024 #ifndef DBUS_MARSHAL_VALIDATE_H
00025 #define DBUS_MARSHAL_VALIDATE_H
00026 
00027 #include <config.h>
00028 
00029 #ifndef PACKAGE
00030 #error "config.h not included here"
00031 #endif
00032 
00042 typedef enum
00043 {
00044   DBUS_VALIDATION_MODE_WE_TRUST_THIS_DATA_ABSOLUTELY,
00045   DBUS_VALIDATION_MODE_DATA_IS_UNTRUSTED
00046 } DBusValidationMode;
00047 
00055 typedef enum
00056 {
00057 #define _DBUS_NEGATIVE_VALIDITY_COUNT 4
00058   DBUS_VALIDITY_UNKNOWN_OOM_ERROR = -4, 
00059   DBUS_INVALID_FOR_UNKNOWN_REASON = -3,
00060   DBUS_VALID_BUT_INCOMPLETE = -2,
00061   DBUS_VALIDITY_UNKNOWN = -1,
00062   DBUS_VALID = 0, 
00063   DBUS_INVALID_UNKNOWN_TYPECODE = 1,
00064   DBUS_INVALID_MISSING_ARRAY_ELEMENT_TYPE = 2,
00065   DBUS_INVALID_SIGNATURE_TOO_LONG = 3, /* this one is impossible right now since
00066                                         * you can't put a too-long value in a byte
00067                                         */
00068   DBUS_INVALID_EXCEEDED_MAXIMUM_ARRAY_RECURSION = 4,
00069   DBUS_INVALID_EXCEEDED_MAXIMUM_STRUCT_RECURSION = 5,
00070   DBUS_INVALID_STRUCT_ENDED_BUT_NOT_STARTED = 6,
00071   DBUS_INVALID_STRUCT_STARTED_BUT_NOT_ENDED = 7,
00072   DBUS_INVALID_STRUCT_HAS_NO_FIELDS = 8,
00073   DBUS_INVALID_ALIGNMENT_PADDING_NOT_NUL = 9,
00074   DBUS_INVALID_BOOLEAN_NOT_ZERO_OR_ONE = 10,
00075   DBUS_INVALID_NOT_ENOUGH_DATA = 11,
00076   DBUS_INVALID_TOO_MUCH_DATA = 12, 
00077   DBUS_INVALID_BAD_BYTE_ORDER = 13,
00078   DBUS_INVALID_BAD_PROTOCOL_VERSION = 14,
00079   DBUS_INVALID_BAD_MESSAGE_TYPE = 15,
00080   DBUS_INVALID_BAD_SERIAL = 16,
00081   DBUS_INVALID_INSANE_FIELDS_ARRAY_LENGTH = 17,
00082   DBUS_INVALID_INSANE_BODY_LENGTH = 18,
00083   DBUS_INVALID_MESSAGE_TOO_LONG = 19,
00084   DBUS_INVALID_HEADER_FIELD_CODE = 20,
00085   DBUS_INVALID_HEADER_FIELD_HAS_WRONG_TYPE = 21,
00086   DBUS_INVALID_USES_LOCAL_INTERFACE = 22,
00087   DBUS_INVALID_USES_LOCAL_PATH = 23,
00088   DBUS_INVALID_HEADER_FIELD_APPEARS_TWICE = 24,
00089   DBUS_INVALID_BAD_DESTINATION = 25,
00090   DBUS_INVALID_BAD_INTERFACE = 26,
00091   DBUS_INVALID_BAD_MEMBER = 27,
00092   DBUS_INVALID_BAD_ERROR_NAME = 28,
00093   DBUS_INVALID_BAD_SENDER = 29,
00094   DBUS_INVALID_MISSING_PATH = 30,
00095   DBUS_INVALID_MISSING_INTERFACE = 31,
00096   DBUS_INVALID_MISSING_MEMBER = 32,
00097   DBUS_INVALID_MISSING_ERROR_NAME = 33,
00098   DBUS_INVALID_MISSING_REPLY_SERIAL = 34,
00099   DBUS_INVALID_LENGTH_OUT_OF_BOUNDS = 35,
00100   DBUS_INVALID_ARRAY_LENGTH_EXCEEDS_MAXIMUM = 36,
00101   DBUS_INVALID_BAD_PATH = 37,
00102   DBUS_INVALID_SIGNATURE_LENGTH_OUT_OF_BOUNDS = 38,
00103   DBUS_INVALID_BAD_UTF8_IN_STRING = 39,
00104   DBUS_INVALID_ARRAY_LENGTH_INCORRECT = 40,
00105   DBUS_INVALID_VARIANT_SIGNATURE_LENGTH_OUT_OF_BOUNDS = 41,
00106   DBUS_INVALID_VARIANT_SIGNATURE_BAD = 42,
00107   DBUS_INVALID_VARIANT_SIGNATURE_EMPTY = 43,
00108   DBUS_INVALID_VARIANT_SIGNATURE_SPECIFIES_MULTIPLE_VALUES = 44,
00109   DBUS_INVALID_VARIANT_SIGNATURE_MISSING_NUL = 45,
00110   DBUS_INVALID_STRING_MISSING_NUL = 46,
00111   DBUS_INVALID_SIGNATURE_MISSING_NUL = 47,
00112   DBUS_INVALID_EXCEEDED_MAXIMUM_DICT_ENTRY_RECURSION = 48,
00113   DBUS_INVALID_DICT_ENTRY_ENDED_BUT_NOT_STARTED = 49,
00114   DBUS_INVALID_DICT_ENTRY_STARTED_BUT_NOT_ENDED = 50,
00115   DBUS_INVALID_DICT_ENTRY_HAS_NO_FIELDS = 51,
00116   DBUS_INVALID_DICT_ENTRY_HAS_ONLY_ONE_FIELD = 52,
00117   DBUS_INVALID_DICT_ENTRY_HAS_TOO_MANY_FIELDS = 53,
00118   DBUS_INVALID_DICT_ENTRY_NOT_INSIDE_ARRAY = 54,
00119   DBUS_INVALID_DICT_KEY_MUST_BE_BASIC_TYPE = 55,
00120   DBUS_VALIDITY_LAST
00121 } DBusValidity;
00122 
00123 DBusValidity _dbus_validate_signature_with_reason (const DBusString *type_str,
00124                                                    int               type_pos,
00125                                                    int               len);
00126 DBusValidity _dbus_validate_body_with_reason      (const DBusString *expected_signature,
00127                                                    int               expected_signature_start,
00128                                                    int               byte_order,
00129                                                    int              *bytes_remaining,
00130                                                    const DBusString *value_str,
00131                                                    int               value_pos,
00132                                                    int               len);
00133 
00134 dbus_bool_t _dbus_validate_path       (const DBusString *str,
00135                                        int               start,
00136                                        int               len);
00137 dbus_bool_t _dbus_validate_interface  (const DBusString *str,
00138                                        int               start,
00139                                        int               len);
00140 dbus_bool_t _dbus_validate_member     (const DBusString *str,
00141                                        int               start,
00142                                        int               len);
00143 dbus_bool_t _dbus_validate_error_name (const DBusString *str,
00144                                        int               start,
00145                                        int               len);
00146 dbus_bool_t _dbus_validate_bus_name   (const DBusString *str,
00147                                        int               start,
00148                                        int               len);
00149 dbus_bool_t _dbus_validate_signature  (const DBusString *str,
00150                                        int               start,
00151                                        int               len);
00152 
00153 #ifdef DBUS_DISABLE_CHECKS
00154 
00155 /* Be sure they don't exist, since we don't want to use them outside of checks
00156  * and so we want the compile failure.
00157  */
00158 #define DECLARE_DBUS_NAME_CHECK(what)
00159 #define DEFINE_DBUS_NAME_CHECK(what)
00160 
00161 #else /* !DBUS_DISABLE_CHECKS */
00162 
00166 #define DECLARE_DBUS_NAME_CHECK(what) \
00167 dbus_bool_t _dbus_check_is_valid_##what (const char *name)
00168 
00171 #define DEFINE_DBUS_NAME_CHECK(what)                                    \
00172 dbus_bool_t                                                             \
00173 _dbus_check_is_valid_##what (const char *name)                          \
00174 {                                                                       \
00175   DBusString str;                                                       \
00176                                                                         \
00177   if (name == NULL)                                                     \
00178     return FALSE;                                                       \
00179                                                                         \
00180   _dbus_string_init_const (&str, name);                                 \
00181   return _dbus_validate_##what (&str, 0,                                \
00182                                 _dbus_string_get_length (&str));        \
00183 }
00184 #endif /* !DBUS_DISABLE_CHECKS */
00185 
00187 DECLARE_DBUS_NAME_CHECK(path);
00189 DECLARE_DBUS_NAME_CHECK(interface);
00191 DECLARE_DBUS_NAME_CHECK(member);
00193 DECLARE_DBUS_NAME_CHECK(error_name);
00195 DECLARE_DBUS_NAME_CHECK(bus_name);
00197 DECLARE_DBUS_NAME_CHECK(signature);
00198 
00201 #endif /* DBUS_MARSHAL_VALIDATE_H */

Generated on Tue Feb 24 16:40:39 2009 for D-Bus by  doxygen 1.5.1