dbus-string.h

00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
00002 /* dbus-string.h String utility class (internal to D-Bus implementation)
00003  * 
00004  * Copyright (C) 2002, 2003 Red Hat, Inc.
00005  * Copyright (C) 2006 Ralf Habacker <ralf.habacker@freenet.de>
00006  *
00007  * Licensed under the Academic Free License version 2.1
00008  * 
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  * 
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022  *
00023  */
00024 
00025 #ifndef DBUS_STRING_H
00026 #define DBUS_STRING_H
00027 
00028 #include <config.h>
00029 
00030 #include <dbus/dbus-memory.h>
00031 #include <dbus/dbus-types.h>
00032 #include <dbus/dbus-sysdeps.h>
00033 
00034 #include <stdarg.h>
00035 
00036 DBUS_BEGIN_DECLS
00037 
00041 struct DBusString
00042 {
00043   const void *dummy1; 
00044   int   dummy2;       
00045   int   dummy3;       
00046   int   dummy4;       
00047   unsigned int dummy5 : 1; 
00048   unsigned int dummy6 : 1; 
00049   unsigned int dummy7 : 1; 
00050   unsigned int dummy8 : 3; 
00051 };
00052 
00053 #ifdef DBUS_DISABLE_ASSERT
00054 /* Some simple inlining hacks; the current linker is not smart enough
00055  * to inline non-exported symbols across files in the library.
00056  * Note that these break type safety (due to the casts)
00057  */
00058 #define _dbus_string_get_data(s) ((char*)(((DBusString*)(s))->dummy1))
00059 #define _dbus_string_get_length(s) (((DBusString*)(s))->dummy2)
00060 #define _dbus_string_set_byte(s, i, b) ((((unsigned char*)(((DBusString*)(s))->dummy1))[(i)]) = (unsigned char) (b))
00061 #define _dbus_string_get_byte(s, i) (((const unsigned char*)(((DBusString*)(s))->dummy1))[(i)])
00062 #define _dbus_string_get_const_data(s) ((const char*)(((DBusString*)(s))->dummy1))
00063 #define _dbus_string_get_const_data_len(s,start,len) (((const char*)(((DBusString*)(s))->dummy1)) + (start))
00064 #endif
00065 
00066 dbus_bool_t   _dbus_string_init                  (DBusString        *str);
00067 void          _dbus_string_init_const            (DBusString        *str,
00068                                                   const char        *value);
00069 void          _dbus_string_init_const_len        (DBusString        *str,
00070                                                   const char        *value,
00071                                                   int                len);
00072 dbus_bool_t   _dbus_string_init_preallocated     (DBusString        *str,
00073                                                   int                allocate_size);
00074 void          _dbus_string_free                  (DBusString        *str);
00075 void          _dbus_string_lock                  (DBusString        *str);
00076 dbus_bool_t   _dbus_string_compact               (DBusString        *str,
00077                                                   int                max_waste);
00078 #ifndef _dbus_string_get_data
00079 char*         _dbus_string_get_data              (DBusString        *str);
00080 #endif /* _dbus_string_get_data */
00081 #ifndef _dbus_string_get_const_data
00082 const char*   _dbus_string_get_const_data        (const DBusString  *str);
00083 #endif /* _dbus_string_get_const_data */
00084 char*         _dbus_string_get_data_len          (DBusString        *str,
00085                                                   int                start,
00086                                                   int                len);
00087 #ifndef _dbus_string_get_const_data_len
00088 const char*   _dbus_string_get_const_data_len    (const DBusString  *str,
00089                                                   int                start,
00090                                                   int                len);
00091 #endif
00092 #ifndef _dbus_string_set_byte
00093 void          _dbus_string_set_byte              (DBusString        *str,
00094                                                   int                i,
00095                                                   unsigned char      byte);
00096 #endif
00097 #ifndef _dbus_string_get_byte
00098 unsigned char _dbus_string_get_byte              (const DBusString  *str,
00099                                                   int                start);
00100 #endif /* _dbus_string_get_byte */
00101 dbus_bool_t   _dbus_string_insert_bytes          (DBusString        *str,
00102                                                   int                i,
00103                                                   int                n_bytes,
00104                                                   unsigned char      byte);
00105 dbus_bool_t   _dbus_string_insert_byte           (DBusString        *str,
00106                                                   int                i,
00107                                                   unsigned char      byte);
00108 dbus_bool_t   _dbus_string_steal_data            (DBusString        *str,
00109                                                   char             **data_return);
00110 dbus_bool_t   _dbus_string_steal_data_len        (DBusString        *str,
00111                                                   char             **data_return,
00112                                                   int                start,
00113                                                   int                len);
00114 dbus_bool_t   _dbus_string_copy_data             (const DBusString  *str,
00115                                                   char             **data_return);
00116 dbus_bool_t   _dbus_string_copy_data_len         (const DBusString  *str,
00117                                                   char             **data_return,
00118                                                   int                start,
00119                                                   int                len);
00120 void          _dbus_string_copy_to_buffer        (const DBusString  *str,
00121                                                   char              *buffer,
00122                                                   int                len);
00123 void          _dbus_string_copy_to_buffer_with_nul (const DBusString  *str,
00124                                                     char              *buffer,
00125                                                     int                avail_len);
00126 #ifndef _dbus_string_get_length
00127 int           _dbus_string_get_length            (const DBusString  *str);
00128 #endif /* !_dbus_string_get_length */
00129 
00130 dbus_bool_t   _dbus_string_lengthen              (DBusString        *str,
00131                                                   int                additional_length);
00132 void          _dbus_string_shorten               (DBusString        *str,
00133                                                   int                length_to_remove);
00134 dbus_bool_t   _dbus_string_set_length            (DBusString        *str,
00135                                                   int                length);
00136 dbus_bool_t   _dbus_string_align_length          (DBusString        *str,
00137                                                   int                alignment);
00138 dbus_bool_t   _dbus_string_alloc_space           (DBusString        *str,
00139                                                   int                extra_bytes);
00140 dbus_bool_t   _dbus_string_append                (DBusString        *str,
00141                                                   const char        *buffer);
00142 dbus_bool_t   _dbus_string_append_len            (DBusString        *str,
00143                                                   const char        *buffer,
00144                                                   int                len);
00145 dbus_bool_t   _dbus_string_append_int            (DBusString        *str,
00146                                                   long               value);
00147 dbus_bool_t   _dbus_string_append_uint           (DBusString        *str,
00148                                                   unsigned long      value);
00149 dbus_bool_t   _dbus_string_append_double         (DBusString        *str,
00150                                                   double             value);
00151 dbus_bool_t   _dbus_string_append_byte           (DBusString        *str,
00152                                                   unsigned char      byte);
00153 dbus_bool_t   _dbus_string_append_unichar        (DBusString        *str,
00154                                                   dbus_unichar_t     ch);
00155 dbus_bool_t   _dbus_string_append_4_aligned      (DBusString        *str,
00156                                                   const unsigned char octets[4]);
00157 dbus_bool_t   _dbus_string_append_8_aligned      (DBusString        *str,
00158                                                   const unsigned char octets[8]);
00159 dbus_bool_t   _dbus_string_append_printf         (DBusString        *str,
00160                                                   const char        *format,
00161                                                   ...) _DBUS_GNUC_PRINTF (2, 3);
00162 dbus_bool_t   _dbus_string_append_printf_valist  (DBusString        *str,
00163                                                   const char        *format,
00164                                                   va_list            args);
00165 dbus_bool_t   _dbus_string_insert_2_aligned      (DBusString        *str,
00166                                                   int                insert_at,
00167                                                   const unsigned char octets[2]);
00168 dbus_bool_t   _dbus_string_insert_4_aligned      (DBusString        *str,
00169                                                   int                insert_at,
00170                                                   const unsigned char octets[4]);
00171 dbus_bool_t   _dbus_string_insert_8_aligned      (DBusString        *str,
00172                                                   int                insert_at,
00173                                                   const unsigned char octets[8]);
00174 dbus_bool_t   _dbus_string_insert_alignment      (DBusString        *str,
00175                                                   int               *insert_at,
00176                                                   int                alignment);
00177 void          _dbus_string_delete                (DBusString        *str,
00178                                                   int                start,
00179                                                   int                len);
00180 dbus_bool_t   _dbus_string_move                  (DBusString        *source,
00181                                                   int                start,
00182                                                   DBusString        *dest,
00183                                                   int                insert_at);
00184 dbus_bool_t   _dbus_string_copy                  (const DBusString  *source,
00185                                                   int                start,
00186                                                   DBusString        *dest,
00187                                                   int                insert_at);
00188 dbus_bool_t   _dbus_string_move_len              (DBusString        *source,
00189                                                   int                start,
00190                                                   int                len,
00191                                                   DBusString        *dest,
00192                                                   int                insert_at);
00193 dbus_bool_t   _dbus_string_copy_len              (const DBusString  *source,
00194                                                   int                start,
00195                                                   int                len,
00196                                                   DBusString        *dest,
00197                                                   int                insert_at);
00198 dbus_bool_t   _dbus_string_replace_len           (const DBusString  *source,
00199                                                   int                start,
00200                                                   int                len,
00201                                                   DBusString        *dest,
00202                                                   int                replace_at,
00203                                                   int                replace_len);
00204 dbus_bool_t   _dbus_string_split_on_byte         (DBusString        *source,
00205                                                   unsigned char      byte,
00206                                                   DBusString        *tail);
00207 void          _dbus_string_get_unichar           (const DBusString  *str,
00208                                                   int                start,
00209                                                   dbus_unichar_t    *ch_return,
00210                                                   int               *end_return);
00211 dbus_bool_t   _dbus_string_parse_int             (const DBusString  *str,
00212                                                   int                start,
00213                                                   long              *value_return,
00214                                                   int               *end_return);
00215 dbus_bool_t   _dbus_string_parse_uint            (const DBusString  *str,
00216                                                   int                start,
00217                                                   unsigned long     *value_return,
00218                                                   int               *end_return);
00219 dbus_bool_t   _dbus_string_parse_double          (const DBusString  *str,
00220                                                   int                start,
00221                                                   double            *value,
00222                                                   int               *end_return);
00223 dbus_bool_t   _dbus_string_find                  (const DBusString  *str,
00224                                                   int                start,
00225                                                   const char        *substr,
00226                                                   int               *found);
00227 dbus_bool_t   _dbus_string_find_eol               (const DBusString *str,
00228                                                   int               start,
00229                                                   int               *found,
00230                                                   int               *found_len);
00231 dbus_bool_t   _dbus_string_find_to               (const DBusString  *str,
00232                                                   int                start,
00233                                                   int                end,
00234                                                   const char        *substr,
00235                                                   int               *found);
00236 dbus_bool_t   _dbus_string_find_byte_backward    (const DBusString  *str,
00237                                                   int                start,
00238                                                   unsigned char      byte,
00239                                                   int               *found);
00240 dbus_bool_t   _dbus_string_find_blank            (const DBusString  *str,
00241                                                   int                start,
00242                                                   int               *found);
00243 void          _dbus_string_skip_blank            (const DBusString  *str,
00244                                                   int                start,
00245                                                   int               *end);
00246 void          _dbus_string_skip_white            (const DBusString  *str,
00247                                                   int                start,
00248                                                   int               *end);
00249 void          _dbus_string_skip_white_reverse    (const DBusString  *str,
00250                                                   int                end,
00251                                                   int               *start);
00252 dbus_bool_t   _dbus_string_equal                 (const DBusString  *a,
00253                                                   const DBusString  *b);
00254 dbus_bool_t   _dbus_string_equal_c_str           (const DBusString  *a,
00255                                                   const char        *c_str);
00256 dbus_bool_t   _dbus_string_equal_len             (const DBusString  *a,
00257                                                   const DBusString  *b,
00258                                                   int                len);
00259 dbus_bool_t   _dbus_string_equal_substring       (const DBusString  *a,
00260                                                   int                a_start,
00261                                                   int                a_len,
00262                                                   const DBusString  *b,
00263                                                   int                b_start);
00264 dbus_bool_t   _dbus_string_starts_with_c_str     (const DBusString  *a,
00265                                                   const char        *c_str);
00266 dbus_bool_t   _dbus_string_ends_with_c_str       (const DBusString  *a,
00267                                                   const char        *c_str);
00268 dbus_bool_t   _dbus_string_pop_line              (DBusString        *source,
00269                                                   DBusString        *dest);
00270 void          _dbus_string_delete_first_word     (DBusString        *str);
00271 void          _dbus_string_delete_leading_blanks (DBusString        *str);
00272 void          _dbus_string_chop_white            (DBusString        *str); 
00273 dbus_bool_t   _dbus_string_append_byte_as_hex    (DBusString        *str,
00274                                                   int                byte);
00275 dbus_bool_t   _dbus_string_hex_encode            (const DBusString  *source,
00276                                                   int                start,
00277                                                   DBusString        *dest,
00278                                                   int                insert_at);
00279 dbus_bool_t   _dbus_string_hex_decode            (const DBusString  *source,
00280                                                   int                start,
00281                                                   int               *end_return,
00282                                                   DBusString        *dest,
00283                                                   int                insert_at);
00284 dbus_bool_t   _dbus_string_validate_ascii        (const DBusString  *str,
00285                                                   int                start,
00286                                                   int                len);
00287 dbus_bool_t   _dbus_string_validate_utf8         (const DBusString  *str,
00288                                                   int                start,
00289                                                   int                len);
00290 dbus_bool_t   _dbus_string_validate_nul          (const DBusString  *str,
00291                                                   int                start,
00292                                                   int                len);
00293 void          _dbus_string_zero                  (DBusString        *str);
00294 
00295 
00301 #define _DBUS_STRING_ALLOCATION_PADDING 8
00302 
00310 #define _DBUS_STRING_DEFINE_STATIC(name, str)                           \
00311   static const char _dbus_static_string_##name[] = str;                 \
00312   static const DBusString name = { _dbus_static_string_##name,          \
00313                                    sizeof(_dbus_static_string_##name),  \
00314                                    sizeof(_dbus_static_string_##name) + \
00315                                    _DBUS_STRING_ALLOCATION_PADDING,     \
00316                                    sizeof(_dbus_static_string_##name),  \
00317                                    TRUE, TRUE, FALSE, 0 }
00318 
00319 DBUS_END_DECLS
00320 
00321 #endif /* DBUS_STRING_H */

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