dbus-string.h

00001 /* -*- mode: C; c-file-style: "gnu" -*- */
00002 /* dbus-string.h String utility class (internal to D-Bus implementation)
00003  * 
00004  * Copyright (C) 2002, 2003 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_STRING_H
00025 #define DBUS_STRING_H
00026 
00027 #include <config.h>
00028 
00029 #include <dbus/dbus-memory.h>
00030 #include <dbus/dbus-types.h>
00031 #include <dbus/dbus-sysdeps.h>
00032 
00033 #include <stdarg.h>
00034 
00035 DBUS_BEGIN_DECLS
00036 
00040 struct DBusString
00041 {
00042   const void *dummy1; 
00043   int   dummy2;       
00044   int   dummy3;       
00045   int   dummy4;       
00046   unsigned int dummy5 : 1; 
00047   unsigned int dummy6 : 1; 
00048   unsigned int dummy7 : 1; 
00049   unsigned int dummy8 : 3; 
00050 };
00051 
00052 #ifdef DBUS_DISABLE_ASSERT
00053 /* Some simple inlining hacks; the current linker is not smart enough
00054  * to inline non-exported symbols across files in the library.
00055  * Note that these break type safety (due to the casts)
00056  */
00057 #define _dbus_string_get_data(s) ((char*)(((DBusString*)(s))->dummy1))
00058 #define _dbus_string_get_length(s) (((DBusString*)(s))->dummy2)
00059 #define _dbus_string_set_byte(s, i, b) ((((unsigned char*)(((DBusString*)(s))->dummy1))[(i)]) = (unsigned char) (b))
00060 #define _dbus_string_get_byte(s, i) (((const unsigned char*)(((DBusString*)(s))->dummy1))[(i)])
00061 #define _dbus_string_get_const_data(s) ((const char*)(((DBusString*)(s))->dummy1))
00062 #define _dbus_string_get_const_data_len(s,start,len) (((const char*)(((DBusString*)(s))->dummy1)) + (start))
00063 #endif
00064 
00065 dbus_bool_t   _dbus_string_init                  (DBusString        *str);
00066 void          _dbus_string_init_const            (DBusString        *str,
00067                                                   const char        *value);
00068 void          _dbus_string_init_const_len        (DBusString        *str,
00069                                                   const char        *value,
00070                                                   int                len);
00071 dbus_bool_t   _dbus_string_init_preallocated     (DBusString        *str,
00072                                                   int                allocate_size);
00073 void          _dbus_string_free                  (DBusString        *str);
00074 void          _dbus_string_lock                  (DBusString        *str);
00075 #ifndef _dbus_string_get_data
00076 char*         _dbus_string_get_data              (DBusString        *str);
00077 #endif /* _dbus_string_get_data */
00078 #ifndef _dbus_string_get_const_data
00079 const char*   _dbus_string_get_const_data        (const DBusString  *str);
00080 #endif /* _dbus_string_get_const_data */
00081 char*         _dbus_string_get_data_len          (DBusString        *str,
00082                                                   int                start,
00083                                                   int                len);
00084 #ifndef _dbus_string_get_const_data_len
00085 const char*   _dbus_string_get_const_data_len    (const DBusString  *str,
00086                                                   int                start,
00087                                                   int                len);
00088 #endif
00089 #ifndef _dbus_string_set_byte
00090 void          _dbus_string_set_byte              (DBusString        *str,
00091                                                   int                i,
00092                                                   unsigned char      byte);
00093 #endif
00094 #ifndef _dbus_string_get_byte
00095 unsigned char _dbus_string_get_byte              (const DBusString  *str,
00096                                                   int                start);
00097 #endif /* _dbus_string_get_byte */
00098 dbus_bool_t   _dbus_string_insert_bytes          (DBusString        *str,
00099                                                   int                i,
00100                                                   int                n_bytes,
00101                                                   unsigned char      byte);
00102 dbus_bool_t   _dbus_string_insert_byte           (DBusString        *str,
00103                                                   int                i,
00104                                                   unsigned char      byte);
00105 dbus_bool_t   _dbus_string_steal_data            (DBusString        *str,
00106                                                   char             **data_return);
00107 dbus_bool_t   _dbus_string_steal_data_len        (DBusString        *str,
00108                                                   char             **data_return,
00109                                                   int                start,
00110                                                   int                len);
00111 dbus_bool_t   _dbus_string_copy_data             (const DBusString  *str,
00112                                                   char             **data_return);
00113 dbus_bool_t   _dbus_string_copy_data_len         (const DBusString  *str,
00114                                                   char             **data_return,
00115                                                   int                start,
00116                                                   int                len);
00117 void          _dbus_string_copy_to_buffer        (const DBusString  *str,
00118                                                   char              *buffer,
00119                                                   int                len);
00120 #ifndef _dbus_string_get_length
00121 int           _dbus_string_get_length            (const DBusString  *str);
00122 #endif /* !_dbus_string_get_length */
00123 
00124 dbus_bool_t   _dbus_string_lengthen              (DBusString        *str,
00125                                                   int                additional_length);
00126 void          _dbus_string_shorten               (DBusString        *str,
00127                                                   int                length_to_remove);
00128 dbus_bool_t   _dbus_string_set_length            (DBusString        *str,
00129                                                   int                length);
00130 dbus_bool_t   _dbus_string_align_length          (DBusString        *str,
00131                                                   int                alignment);
00132 dbus_bool_t   _dbus_string_alloc_space           (DBusString        *str,
00133                                                   int                extra_bytes);
00134 dbus_bool_t   _dbus_string_append                (DBusString        *str,
00135                                                   const char        *buffer);
00136 dbus_bool_t   _dbus_string_append_len            (DBusString        *str,
00137                                                   const char        *buffer,
00138                                                   int                len);
00139 dbus_bool_t   _dbus_string_append_int            (DBusString        *str,
00140                                                   long               value);
00141 dbus_bool_t   _dbus_string_append_uint           (DBusString        *str,
00142                                                   unsigned long      value);
00143 dbus_bool_t   _dbus_string_append_double         (DBusString        *str,
00144                                                   double             value);
00145 dbus_bool_t   _dbus_string_append_byte           (DBusString        *str,
00146                                                   unsigned char      byte);
00147 dbus_bool_t   _dbus_string_append_unichar        (DBusString        *str,
00148                                                   dbus_unichar_t     ch);
00149 dbus_bool_t   _dbus_string_append_4_aligned      (DBusString        *str,
00150                                                   const unsigned char octets[4]);
00151 dbus_bool_t   _dbus_string_append_8_aligned      (DBusString        *str,
00152                                                   const unsigned char octets[8]);
00153 dbus_bool_t   _dbus_string_append_printf         (DBusString        *str,
00154                                                   const char        *format,
00155                                                   ...) _DBUS_GNUC_PRINTF (2, 3);
00156 dbus_bool_t   _dbus_string_append_printf_valist  (DBusString        *str,
00157                                                   const char        *format,
00158                                                   va_list            args);
00159 dbus_bool_t   _dbus_string_insert_2_aligned      (DBusString        *str,
00160                                                   int                insert_at,
00161                                                   const unsigned char octets[2]);
00162 dbus_bool_t   _dbus_string_insert_4_aligned      (DBusString        *str,
00163                                                   int                insert_at,
00164                                                   const unsigned char octets[4]);
00165 dbus_bool_t   _dbus_string_insert_8_aligned      (DBusString        *str,
00166                                                   int                insert_at,
00167                                                   const unsigned char octets[8]);
00168 dbus_bool_t   _dbus_string_insert_alignment      (DBusString        *str,
00169                                                   int               *insert_at,
00170                                                   int                alignment);
00171 void          _dbus_string_delete                (DBusString        *str,
00172                                                   int                start,
00173                                                   int                len);
00174 dbus_bool_t   _dbus_string_move                  (DBusString        *source,
00175                                                   int                start,
00176                                                   DBusString        *dest,
00177                                                   int                insert_at);
00178 dbus_bool_t   _dbus_string_copy                  (const DBusString  *source,
00179                                                   int                start,
00180                                                   DBusString        *dest,
00181                                                   int                insert_at);
00182 dbus_bool_t   _dbus_string_move_len              (DBusString        *source,
00183                                                   int                start,
00184                                                   int                len,
00185                                                   DBusString        *dest,
00186                                                   int                insert_at);
00187 dbus_bool_t   _dbus_string_copy_len              (const DBusString  *source,
00188                                                   int                start,
00189                                                   int                len,
00190                                                   DBusString        *dest,
00191                                                   int                insert_at);
00192 dbus_bool_t   _dbus_string_replace_len           (const DBusString  *source,
00193                                                   int                start,
00194                                                   int                len,
00195                                                   DBusString        *dest,
00196                                                   int                replace_at,
00197                                                   int                replace_len);
00198 void          _dbus_string_get_unichar           (const DBusString  *str,
00199                                                   int                start,
00200                                                   dbus_unichar_t    *ch_return,
00201                                                   int               *end_return);
00202 dbus_bool_t   _dbus_string_parse_int             (const DBusString  *str,
00203                                                   int                start,
00204                                                   long              *value_return,
00205                                                   int               *end_return);
00206 dbus_bool_t   _dbus_string_parse_uint            (const DBusString  *str,
00207                                                   int                start,
00208                                                   unsigned long     *value_return,
00209                                                   int               *end_return);
00210 dbus_bool_t   _dbus_string_parse_double          (const DBusString  *str,
00211                                                   int                start,
00212                                                   double            *value,
00213                                                   int               *end_return);
00214 dbus_bool_t   _dbus_string_find                  (const DBusString  *str,
00215                                                   int                start,
00216                                                   const char        *substr,
00217                                                   int               *found);
00218 dbus_bool_t   _dbus_string_find_to               (const DBusString  *str,
00219                                                   int                start,
00220                                                   int                end,
00221                                                   const char        *substr,
00222                                                   int               *found);
00223 dbus_bool_t   _dbus_string_find_byte_backward    (const DBusString  *str,
00224                                                   int                start,
00225                                                   unsigned char      byte,
00226                                                   int               *found);
00227 dbus_bool_t   _dbus_string_find_blank            (const DBusString  *str,
00228                                                   int                start,
00229                                                   int               *found);
00230 void          _dbus_string_skip_blank            (const DBusString  *str,
00231                                                   int                start,
00232                                                   int               *end);
00233 void          _dbus_string_skip_white            (const DBusString  *str,
00234                                                   int                start,
00235                                                   int               *end);
00236 void          _dbus_string_skip_white_reverse    (const DBusString  *str,
00237                                                   int                end,
00238                                                   int               *start);
00239 dbus_bool_t   _dbus_string_equal                 (const DBusString  *a,
00240                                                   const DBusString  *b);
00241 dbus_bool_t   _dbus_string_equal_c_str           (const DBusString  *a,
00242                                                   const char        *c_str);
00243 dbus_bool_t   _dbus_string_equal_len             (const DBusString  *a,
00244                                                   const DBusString  *b,
00245                                                   int                len);
00246 dbus_bool_t   _dbus_string_equal_substring       (const DBusString  *a,
00247                                                   int                a_start,
00248                                                   int                a_len,
00249                                                   const DBusString  *b,
00250                                                   int                b_start);
00251 dbus_bool_t   _dbus_string_starts_with_c_str     (const DBusString  *a,
00252                                                   const char        *c_str);
00253 dbus_bool_t   _dbus_string_ends_with_c_str       (const DBusString  *a,
00254                                                   const char        *c_str);
00255 dbus_bool_t   _dbus_string_pop_line              (DBusString        *source,
00256                                                   DBusString        *dest);
00257 void          _dbus_string_delete_first_word     (DBusString        *str);
00258 void          _dbus_string_delete_leading_blanks (DBusString        *str);
00259 void          _dbus_string_chop_white            (DBusString        *str); 
00260 dbus_bool_t   _dbus_string_append_byte_as_hex    (DBusString        *str,
00261                                                   int                byte);
00262 dbus_bool_t   _dbus_string_hex_encode            (const DBusString  *source,
00263                                                   int                start,
00264                                                   DBusString        *dest,
00265                                                   int                insert_at);
00266 dbus_bool_t   _dbus_string_hex_decode            (const DBusString  *source,
00267                                                   int                start,
00268                                                   int               *end_return,
00269                                                   DBusString        *dest,
00270                                                   int                insert_at);
00271 dbus_bool_t   _dbus_string_validate_ascii        (const DBusString  *str,
00272                                                   int                start,
00273                                                   int                len);
00274 dbus_bool_t   _dbus_string_validate_utf8         (const DBusString  *str,
00275                                                   int                start,
00276                                                   int                len);
00277 dbus_bool_t   _dbus_string_validate_nul          (const DBusString  *str,
00278                                                   int                start,
00279                                                   int                len);
00280 void          _dbus_string_zero                  (DBusString        *str);
00281 
00282 
00288 #define _DBUS_STRING_ALLOCATION_PADDING 8
00289 
00297 #define _DBUS_STRING_DEFINE_STATIC(name, str)                           \
00298   static const char _dbus_static_string_##name[] = str;                 \
00299   static const DBusString name = { _dbus_static_string_##name,          \
00300                                    sizeof(_dbus_static_string_##name),  \
00301                                    sizeof(_dbus_static_string_##name) + \
00302                                    _DBUS_STRING_ALLOCATION_PADDING,     \
00303                                    sizeof(_dbus_static_string_##name),  \
00304                                    TRUE, TRUE, FALSE, 0 }
00305 
00306 DBUS_END_DECLS
00307 
00308 #endif /* DBUS_STRING_H */

Generated on Fri Sep 21 18:12:13 2007 for D-Bus by  doxygen 1.5.1