index.html
Main Page
|
modules.html
Modules
|
namespaces.html
Namespace List
|
hierarchy.html
Class Hierarchy
|
annotated.html
Data Structures
|
dirs.html
Directories
|
files.html
File List
|
namespacemembers.html
Namespace Members
|
functions.html
Data Fields
|
pages.html
Related Pages
dir_000004.html
dbus
dbus-string.c
00001
/* -*- mode: C; c-file-style: "gnu" -*- */
00002
/* dbus-string.c String utility class (internal to D-BUS implementation)
00003
*
00004
* Copyright (C) 2002, 2003, 2004, 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
#include "dbus-internals.h"
00025
#include "dbus-string.h"
00026
/* we allow a system header here, for speed/convenience */
00027
#include <string.h>
00028
/* for vsnprintf */
00029
#include <stdio.h>
00030
#define DBUS_CAN_USE_DBUS_STRING_PRIVATE 1
00031
#include "dbus-string-private.h"
00032
#include "dbus-marshal-basic.h"
/* probably should be removed by moving the usage of DBUS_TYPE
00033
* into the marshaling-related files
00034
*/
00035
/* for DBUS_VA_COPY */
00036
#include "dbus-sysdeps.h"
00037
00076
static
void
00077 fixup_alignment (
structDBusRealString.html
DBusRealString
*real)
00078 {
00079
unsigned
char
*aligned;
00080
unsigned
char
*real_block;
00081
unsigned
int
old_align_offset;
00082
00083
/* we have to have extra space in real->allocated for the align offset and nul byte */
00084
group__DBusInternalsUtils.html#ga130
_dbus_assert
(real->
structDBusRealString.html#o1
len
<= real->
structDBusRealString.html#o2
allocated
- _DBUS_STRING_ALLOCATION_PADDING);
00085
00086   old_align_offset = real->
structDBusRealString.html#o7
align_offset
;
00087   real_block = real->
structDBusRealString.html#o0
str
- old_align_offset;
00088
00089   aligned = _DBUS_ALIGN_ADDRESS (real_block, 8);
00090
00091   real->
structDBusRealString.html#o7
align_offset
= aligned - real_block;
00092   real->
structDBusRealString.html#o0
str
= aligned;
00093
00094
if
(old_align_offset != real->
structDBusRealString.html#o7
align_offset
)
00095     {
00096
/* Here comes the suck */
00097       memmove (real_block + real->
structDBusRealString.html#o7
align_offset
,
00098                real_block + old_align_offset,
00099                real->
structDBusRealString.html#o1
len
+ 1);
00100     }
00101
00102
group__DBusInternalsUtils.html#ga130
_dbus_assert
(real->
structDBusRealString.html#o7
align_offset
< 8);
00103
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_DBUS_ALIGN_ADDRESS (real->
structDBusRealString.html#o0
str
, 8) == real->
structDBusRealString.html#o0
str
);
00104 }
00105
00106
static
void
00107 undo_alignment (
structDBusRealString.html
DBusRealString
*real)
00108 {
00109
if
(real->
structDBusRealString.html#o7
align_offset
!= 0)
00110     {
00111       memmove (real->
structDBusRealString.html#o0
str
- real->
structDBusRealString.html#o7
align_offset
,
00112                real->
structDBusRealString.html#o0
str
,
00113                real->
structDBusRealString.html#o1
len
+ 1);
00114
00115       real->
structDBusRealString.html#o0
str
= real->
structDBusRealString.html#o0
str
- real->
structDBusRealString.html#o7
align_offset
;
00116       real->
structDBusRealString.html#o7
align_offset
= 0;
00117     }
00118 }
00119
00129
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga5
00130
group__DBusString.html#ga5
_dbus_string_init_preallocated
(
structDBusString.html
DBusString
*str,
00131
int
allocate_size)
00132 {
00133
structDBusRealString.html
DBusRealString
*real;
00134
00135
group__DBusInternalsUtils.html#ga130
_dbus_assert
(str !=
group__DBusMacros.html#ga4
NULL
);
00136
00137
group__DBusInternalsUtils.html#ga130
_dbus_assert
(
sizeof
(
structDBusString.html
DBusString
) ==
sizeof
(
structDBusRealString.html
DBusRealString
));
00138
00139   real = (DBusRealString*) str;
00140
00141
/* It's very important not to touch anything
00142
* other than real->str if we're going to fail,
00143
* since we also use this function to reset
00144
* an existing string, e.g. in _dbus_string_steal_data()
00145
*/
00146
00147   real->
structDBusRealString.html#o0
str
=
group__DBusMemory.html#ga0
dbus_malloc
(_DBUS_STRING_ALLOCATION_PADDING + allocate_size);
00148
if
(real->
structDBusRealString.html#o0
str
==
group__DBusMacros.html#ga4
NULL
)
00149
return
group__DBusMacros.html#ga3
FALSE
;
00150
00151   real->
structDBusRealString.html#o2
allocated
= _DBUS_STRING_ALLOCATION_PADDING + allocate_size;
00152   real->
structDBusRealString.html#o1
len
= 0;
00153   real->
structDBusRealString.html#o0
str
[real->
structDBusRealString.html#o1
len
] =
'\0'
;
00154
00155   real->
structDBusRealString.html#o3
max_length
=
group__DBusStringInternals.html#ga0
_DBUS_STRING_MAX_MAX_LENGTH
;
00156   real->
structDBusRealString.html#o4
constant
=
group__DBusMacros.html#ga3
FALSE
;
00157   real->
structDBusRealString.html#o5
locked
=
group__DBusMacros.html#ga3
FALSE
;
00158   real->
structDBusRealString.html#o6
invalid
=
group__DBusMacros.html#ga3
FALSE
;
00159   real->
structDBusRealString.html#o7
align_offset
= 0;
00160
00161   fixup_alignment (real);
00162
00163
return
group__DBusMacros.html#ga2
TRUE
;
00164 }
00165
00173
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga6
00174
group__DBusString.html#ga6
_dbus_string_init
(
structDBusString.html
DBusString
*str)
00175 {
00176
return
group__DBusString.html#ga5
_dbus_string_init_preallocated
(str, 0);
00177 }
00178
00179
#ifdef DBUS_BUILD_TESTS
00180
/* The max length thing is sort of a historical artifact
00181
* from a feature that turned out to be dumb; perhaps
00182
* we should purge it entirely. The problem with
00183
* the feature is that it looks like memory allocation
00184
* failure, but is not a transient or resolvable failure.
00185
*/
00186
static
void
00187 set_max_length (
structDBusString.html
DBusString
*str,
00188
int
max_length)
00189 {
00190
structDBusRealString.html
DBusRealString
*real;
00191
00192   real = (
structDBusRealString.html
DBusRealString
*) str;
00193
00194   real->
structDBusRealString.html#o3
max_length
= max_length;
00195 }
00196
#endif
/* DBUS_BUILD_TESTS */
00197
00207
void
group__DBusString.html#ga7
00208
group__DBusString.html#ga7
_dbus_string_init_const
(
structDBusString.html
DBusString
*str,
00209
const
char
*value)
00210 {
00211
group__DBusInternalsUtils.html#ga130
_dbus_assert
(value !=
group__DBusMacros.html#ga4
NULL
);
00212
00213
group__DBusString.html#ga8
_dbus_string_init_const_len
(str, value,
00214                                strlen (value));
00215 }
00216
00227
void
group__DBusString.html#ga8
00228
group__DBusString.html#ga8
_dbus_string_init_const_len
(
structDBusString.html
DBusString
*str,
00229
const
char
*value,
00230
int
len)
00231 {
00232
structDBusRealString.html
DBusRealString
*real;
00233
00234
group__DBusInternalsUtils.html#ga130
_dbus_assert
(str !=
group__DBusMacros.html#ga4
NULL
);
00235
group__DBusInternalsUtils.html#ga130
_dbus_assert
(value !=
group__DBusMacros.html#ga4
NULL
);
00236
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len <=
group__DBusStringInternals.html#ga0
_DBUS_STRING_MAX_MAX_LENGTH
);
00237
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len >= 0);
00238
00239   real = (
structDBusRealString.html
DBusRealString
*) str;
00240
00241   real->
structDBusRealString.html#o0
str
= (
unsigned
char
*) value;
00242   real->
structDBusRealString.html#o1
len
= len;
00243   real->
structDBusRealString.html#o2
allocated
= real->
structDBusRealString.html#o1
len
+ _DBUS_STRING_ALLOCATION_PADDING;
/* a lie, just to avoid special-case assertions... */
00244   real->
structDBusRealString.html#o3
max_length
= real->
structDBusRealString.html#o1
len
+ 1;
00245   real->
structDBusRealString.html#o4
constant
=
group__DBusMacros.html#ga2
TRUE
;
00246   real->
structDBusRealString.html#o5
locked
=
group__DBusMacros.html#ga2
TRUE
;
00247   real->
structDBusRealString.html#o6
invalid
=
group__DBusMacros.html#ga3
FALSE
;
00248   real->
structDBusRealString.html#o7
align_offset
= 0;
00249
00250
/* We don't require const strings to be 8-byte aligned as the
00251
* memory is coming from elsewhere.
00252
*/
00253 }
00254
00260
void
group__DBusString.html#ga9
00261
group__DBusString.html#ga9
_dbus_string_free
(
structDBusString.html
DBusString
*str)
00262 {
00263
structDBusRealString.html
DBusRealString
*real = (
structDBusRealString.html
DBusRealString
*) str;
00264
group__DBusStringInternals.html#ga1
DBUS_GENERIC_STRING_PREAMBLE
(real);
00265
00266
if
(real->
structDBusRealString.html#o4
constant
)
00267
return
;
00268
group__DBusMemory.html#ga3
dbus_free
(real->
structDBusRealString.html#o0
str
- real->
structDBusRealString.html#o7
align_offset
);
00269
00270   real->
structDBusRealString.html#o6
invalid
=
group__DBusMacros.html#ga2
TRUE
;
00271 }
00272
00273
#ifdef DBUS_BUILD_TESTS
00274
/* Not using this feature at the moment,
00275
* so marked DBUS_BUILD_TESTS-only
00276
*/
00286
void
00287 _dbus_string_lock (
structDBusString.html
DBusString
*str)
00288 {
00289
group__DBusStringInternals.html#ga3
DBUS_LOCKED_STRING_PREAMBLE
(str);
/* can lock multiple times */
00290
00291   real->
structDBusRealString.html#o5
locked
=
group__DBusMacros.html#ga2
TRUE
;
00292
00293
/* Try to realloc to avoid excess memory usage, since
00294
* we know we won't change the string further
00295
*/
00296
#define MAX_WASTE 48
00297
if
(real->
structDBusRealString.html#o2
allocated
- MAX_WASTE > real->
structDBusRealString.html#o1
len
)
00298     {
00299
unsigned
char
*new_str;
00300
int
new_allocated;
00301
00302       new_allocated = real->
structDBusRealString.html#o1
len
+ _DBUS_STRING_ALLOCATION_PADDING;
00303
00304       new_str =
group__DBusMemory.html#ga2
dbus_realloc
(real->
structDBusRealString.html#o0
str
- real->
structDBusRealString.html#o7
align_offset
,
00305                               new_allocated);
00306
if
(new_str !=
group__DBusMacros.html#ga4
NULL
)
00307         {
00308           real->
structDBusRealString.html#o0
str
= new_str + real->
structDBusRealString.html#o7
align_offset
;
00309           real->
structDBusRealString.html#o2
allocated
= new_allocated;
00310           fixup_alignment (real);
00311         }
00312     }
00313 }
00314
#endif
/* DBUS_BUILD_TESTS */
00315
00316
static
group__DBusTypes.html#ga2
dbus_bool_t
00317 reallocate_for_length (
structDBusRealString.html
DBusRealString
*real,
00318
int
new_length)
00319 {
00320
int
new_allocated;
00321
unsigned
char
*new_str;
00322
00323
/* at least double our old allocation to avoid O(n), avoiding
00324
* overflow
00325
*/
00326
if
(real->
structDBusRealString.html#o2
allocated
> (
group__DBusStringInternals.html#ga0
_DBUS_STRING_MAX_MAX_LENGTH
+ _DBUS_STRING_ALLOCATION_PADDING) / 2)
00327     new_allocated =
group__DBusStringInternals.html#ga0
_DBUS_STRING_MAX_MAX_LENGTH
+ _DBUS_STRING_ALLOCATION_PADDING;
00328
else
00329     new_allocated = real->
structDBusRealString.html#o2
allocated
* 2;
00330
00331
/* if you change the code just above here, run the tests without
00332
* the following assert-only hack before you commit
00333
*/
00334
/* This is keyed off asserts in addition to tests so when you
00335
* disable asserts to profile, you don't get this destroyer
00336
* of profiles.
00337
*/
00338
#ifdef DBUS_DISABLE_ASSERT
00339
#else
00340
#ifdef DBUS_BUILD_TESTS
00341
new_allocated = 0;
/* ensure a realloc every time so that we go
00342
* through all malloc failure codepaths
00343
*/
00344
#endif
/* DBUS_BUILD_TESTS */
00345
#endif
/* !DBUS_DISABLE_ASSERT */
00346
00347
/* But be sure we always alloc at least space for the new length */
00348   new_allocated = MAX (new_allocated,
00349                        new_length + _DBUS_STRING_ALLOCATION_PADDING);
00350
00351
group__DBusInternalsUtils.html#ga130
_dbus_assert
(new_allocated >= real->
structDBusRealString.html#o2
allocated
);
/* code relies on this */
00352   new_str =
group__DBusMemory.html#ga2
dbus_realloc
(real->
structDBusRealString.html#o0
str
- real->
structDBusRealString.html#o7
align_offset
, new_allocated);
00353
if
(_DBUS_UNLIKELY (new_str ==
group__DBusMacros.html#ga4
NULL
))
00354
return
group__DBusMacros.html#ga3
FALSE
;
00355
00356   real->
structDBusRealString.html#o0
str
= new_str + real->
structDBusRealString.html#o7
align_offset
;
00357   real->
structDBusRealString.html#o2
allocated
= new_allocated;
00358   fixup_alignment (real);
00359
00360
return
group__DBusMacros.html#ga2
TRUE
;
00361 }
00362
00363
static
group__DBusTypes.html#ga2
dbus_bool_t
00364 set_length (
structDBusRealString.html
DBusRealString
*real,
00365
int
new_length)
00366 {
00367
/* Note, we are setting the length not including nul termination */
00368
00369
/* exceeding max length is the same as failure to allocate memory */
00370
if
(_DBUS_UNLIKELY (new_length > real->
structDBusRealString.html#o3
max_length
))
00371
return
group__DBusMacros.html#ga3
FALSE
;
00372
else
if
(new_length > (real->
structDBusRealString.html#o2
allocated
- _DBUS_STRING_ALLOCATION_PADDING) &&
00373            _DBUS_UNLIKELY (!reallocate_for_length (real, new_length)))
00374
return
group__DBusMacros.html#ga3
FALSE
;
00375
else
00376     {
00377       real->len = new_length;
00378       real->str[new_length] =
'\0'
;
00379
return
group__DBusMacros.html#ga2
TRUE
;
00380     }
00381 }
00382
00383
static
group__DBusTypes.html#ga2
dbus_bool_t
00384 open_gap (
int
len,
00385
structDBusRealString.html
DBusRealString
*dest,
00386
int
insert_at)
00387 {
00388
if
(len == 0)
00389
return
group__DBusMacros.html#ga2
TRUE
;
00390
00391
if
(len > dest->
structDBusRealString.html#o3
max_length
- dest->
structDBusRealString.html#o1
len
)
00392
return
group__DBusMacros.html#ga3
FALSE
;
/* detected overflow of dest->len + len below */
00393
00394
if
(!set_length (dest, dest->
structDBusRealString.html#o1
len
+ len))
00395
return
group__DBusMacros.html#ga3
FALSE
;
00396
00397   memmove (dest->str + insert_at + len,
00398            dest->str + insert_at,
00399            dest->len - len - insert_at);
00400
00401
return
group__DBusMacros.html#ga2
TRUE
;
00402 }
00403
00404
#ifndef _dbus_string_get_data
00405
00416
char
*
00417 _dbus_string_get_data (
structDBusString.html
DBusString
*str)
00418 {
00419
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
00420
00421
return
(
char
*) real->
structDBusRealString.html#o0
str
;
00422 }
00423
#endif
/* _dbus_string_get_data */
00424
00425
/* only do the function if we don't have the macro */
00426
#ifndef _dbus_string_get_const_data
00427
00433
const
char
*
00434 _dbus_string_get_const_data (
const
structDBusString.html
DBusString
*str)
00435 {
00436
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
00437
00438
return
(
const
char
*) real->
structDBusRealString.html#o0
str
;
00439 }
00440
#endif
/* _dbus_string_get_const_data */
00441
00455
char
*
group__DBusString.html#ga13
00456
group__DBusString.html#ga13
_dbus_string_get_data_len
(
structDBusString.html
DBusString
*str,
00457
int
start,
00458
int
len)
00459 {
00460
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
00461
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start >= 0);
00462
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len >= 0);
00463
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real->len);
00464
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len <= real->len - start);
00465
00466
return
(
char
*) real->
structDBusRealString.html#o0
str
+ start;
00467 }
00468
00469
/* only do the function if we don't have the macro */
00470
#ifndef _dbus_string_get_const_data_len
00471
00479
const
char
*
00480 _dbus_string_get_const_data_len (
const
structDBusString.html
DBusString
*str,
00481
int
start,
00482
int
len)
00483 {
00484
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
00485
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start >= 0);
00486
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len >= 0);
00487
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real->len);
00488
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len <= real->len - start);
00489
00490
return
(
const
char
*) real->
structDBusRealString.html#o0
str
+ start;
00491 }
00492
#endif
/* _dbus_string_get_const_data_len */
00493
00494
/* only do the function if we don't have the macro */
00495
#ifndef _dbus_string_set_byte
00496
00503
void
00504 _dbus_string_set_byte (
structDBusString.html
DBusString
*str,
00505
int
i,
00506
unsigned
char
byte)
00507 {
00508
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
00509
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i < real->len);
00510
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i >= 0);
00511
00512   real->
structDBusRealString.html#o0
str
[i] = byte;
00513 }
00514
#endif
/* _dbus_string_set_byte */
00515
00516
/* only have the function if we didn't create a macro */
00517
#ifndef _dbus_string_get_byte
00518
00527
unsigned
char
00528 _dbus_string_get_byte (
const
structDBusString.html
DBusString
*str,
00529
int
start)
00530 {
00531
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
00532
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real->len);
00533
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start >= 0);
00534
00535
return
real->
structDBusRealString.html#o0
str
[start];
00536 }
00537
#endif
/* _dbus_string_get_byte */
00538
00549
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga14
00550
group__DBusString.html#ga14
_dbus_string_insert_bytes
(
structDBusString.html
DBusString
*str,
00551
int
i,
00552
int
n_bytes,
00553
unsigned
char
byte)
00554 {
00555
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
00556
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i <= real->len);
00557
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i >= 0);
00558
group__DBusInternalsUtils.html#ga130
_dbus_assert
(n_bytes >= 0);
00559
00560
if
(n_bytes == 0)
00561
return
group__DBusMacros.html#ga2
TRUE
;
00562
00563
if
(!open_gap (n_bytes, real, i))
00564
return
group__DBusMacros.html#ga3
FALSE
;
00565
00566   memset (real->
structDBusRealString.html#o0
str
+ i, byte, n_bytes);
00567
00568
return
group__DBusMacros.html#ga2
TRUE
;
00569 }
00570
00579
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga15
00580
group__DBusString.html#ga15
_dbus_string_insert_byte
(
structDBusString.html
DBusString
*str,
00581
int
i,
00582
unsigned
char
byte)
00583 {
00584
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
00585
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i <= real->len);
00586
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i >= 0);
00587
00588
if
(!open_gap (1, real, i))
00589
return
group__DBusMacros.html#ga3
FALSE
;
00590
00591   real->
structDBusRealString.html#o0
str
[i] = byte;
00592
00593
return
group__DBusMacros.html#ga2
TRUE
;
00594 }
00595
00606
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga16
00607
group__DBusString.html#ga16
_dbus_string_steal_data
(
structDBusString.html
DBusString
*str,
00608
char
**data_return)
00609 {
00610
int
old_max_length;
00611
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
00612
group__DBusInternalsUtils.html#ga130
_dbus_assert
(data_return !=
group__DBusMacros.html#ga4
NULL
);
00613
00614   undo_alignment (real);
00615
00616   *data_return = (
char
*) real->
structDBusRealString.html#o0
str
;
00617
00618   old_max_length = real->
structDBusRealString.html#o3
max_length
;
00619
00620
/* reset the string */
00621
if
(!
group__DBusString.html#ga6
_dbus_string_init
(str))
00622     {
00623
/* hrm, put it back then */
00624       real->
structDBusRealString.html#o0
str
= (
unsigned
char
*) *data_return;
00625       *data_return =
group__DBusMacros.html#ga4
NULL
;
00626       fixup_alignment (real);
00627
return
group__DBusMacros.html#ga3
FALSE
;
00628     }
00629
00630   real->
structDBusRealString.html#o3
max_length
= old_max_length;
00631
00632
return
group__DBusMacros.html#ga2
TRUE
;
00633 }
00634
00635
#ifdef DBUS_BUILD_TESTS
00636
00651
group__DBusTypes.html#ga2
dbus_bool_t
00652 _dbus_string_steal_data_len (
structDBusString.html
DBusString
*str,
00653
char
**data_return,
00654
int
start,
00655
int
len)
00656 {
00657
structDBusString.html
DBusString
dest;
00658
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
00659
group__DBusInternalsUtils.html#ga130
_dbus_assert
(data_return !=
group__DBusMacros.html#ga4
NULL
);
00660
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start >= 0);
00661
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len >= 0);
00662
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real->len);
00663
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len <= real->len - start);
00664
00665
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&dest))
00666
return
group__DBusMacros.html#ga3
FALSE
;
00667
00668   set_max_length (&dest, real->
structDBusRealString.html#o3
max_length
);
00669
00670
if
(!
group__DBusString.html#ga41
_dbus_string_move_len
(str, start, len, &dest, 0))
00671     {
00672
group__DBusString.html#ga9
_dbus_string_free
(&dest);
00673
return
group__DBusMacros.html#ga3
FALSE
;
00674     }
00675
00676
group__DBusInternalsUtils.html#ga7
_dbus_warn
(
"Broken code in _dbus_string_steal_data_len(), see @todo, FIXME\n"
);
00677
if
(!
group__DBusString.html#ga16
_dbus_string_steal_data
(&dest, data_return))
00678     {
00679
group__DBusString.html#ga9
_dbus_string_free
(&dest);
00680
return
group__DBusMacros.html#ga3
FALSE
;
00681     }
00682
00683
group__DBusString.html#ga9
_dbus_string_free
(&dest);
00684
return
group__DBusMacros.html#ga2
TRUE
;
00685 }
00686
#endif
/* DBUS_BUILD_TESTS */
00687
00695
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga17
00696
group__DBusString.html#ga17
_dbus_string_copy_data
(
const
structDBusString.html
DBusString
*str,
00697
char
**data_return)
00698 {
00699
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
00700
group__DBusInternalsUtils.html#ga130
_dbus_assert
(data_return !=
group__DBusMacros.html#ga4
NULL
);
00701
00702   *data_return =
group__DBusMemory.html#ga0
dbus_malloc
(real->
structDBusRealString.html#o1
len
+ 1);
00703
if
(*data_return ==
group__DBusMacros.html#ga4
NULL
)
00704
return
group__DBusMacros.html#ga3
FALSE
;
00705
00706   memcpy (*data_return, real->
structDBusRealString.html#o0
str
, real->
structDBusRealString.html#o1
len
+ 1);
00707
00708
return
group__DBusMacros.html#ga2
TRUE
;
00709 }
00710
00719
void
group__DBusString.html#ga18
00720
group__DBusString.html#ga18
_dbus_string_copy_to_buffer
(
const
structDBusString.html
DBusString
*str,
00721
char
*buffer,
00722
int
avail_len)
00723 {
00724
int
copy_len;
00725
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
00726
00727
group__DBusInternalsUtils.html#ga130
_dbus_assert
(avail_len >= 0);
00728
00729   copy_len = MIN (avail_len, real->
structDBusRealString.html#o1
len
+1);
00730   memcpy (buffer, real->
structDBusRealString.html#o0
str
, copy_len);
00731
if
(avail_len > 0 && avail_len == copy_len)
00732     buffer[avail_len-1] =
'\0'
;
00733 }
00734
00735
#ifdef DBUS_BUILD_TESTS
00736
00745
group__DBusTypes.html#ga2
dbus_bool_t
00746 _dbus_string_copy_data_len (
const
structDBusString.html
DBusString
*str,
00747
char
**data_return,
00748
int
start,
00749
int
len)
00750 {
00751
structDBusString.html
DBusString
dest;
00752
00753
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
00754
group__DBusInternalsUtils.html#ga130
_dbus_assert
(data_return !=
group__DBusMacros.html#ga4
NULL
);
00755
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start >= 0);
00756
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len >= 0);
00757
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real->len);
00758
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len <= real->len - start);
00759
00760
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&dest))
00761
return
group__DBusMacros.html#ga3
FALSE
;
00762
00763   set_max_length (&dest, real->
structDBusRealString.html#o3
max_length
);
00764
00765
if
(!
group__DBusString.html#ga42
_dbus_string_copy_len
(str, start, len, &dest, 0))
00766     {
00767
group__DBusString.html#ga9
_dbus_string_free
(&dest);
00768
return
group__DBusMacros.html#ga3
FALSE
;
00769     }
00770
00771
if
(!
group__DBusString.html#ga16
_dbus_string_steal_data
(&dest, data_return))
00772     {
00773
group__DBusString.html#ga9
_dbus_string_free
(&dest);
00774
return
group__DBusMacros.html#ga3
FALSE
;
00775     }
00776
00777
group__DBusString.html#ga9
_dbus_string_free
(&dest);
00778
return
group__DBusMacros.html#ga2
TRUE
;
00779 }
00780
#endif
/* DBUS_BUILD_TESTS */
00781
00782
/* Only have the function if we don't have the macro */
00783
#ifndef _dbus_string_get_length
00784
00789
int
00790 _dbus_string_get_length (
const
structDBusString.html
DBusString
*str)
00791 {
00792
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
00793
00794
return
real->
structDBusRealString.html#o1
len
;
00795 }
00796
#endif
/* !_dbus_string_get_length */
00797
00810
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga19
00811
group__DBusString.html#ga19
_dbus_string_lengthen
(
structDBusString.html
DBusString
*str,
00812
int
additional_length)
00813 {
00814
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
00815
group__DBusInternalsUtils.html#ga130
_dbus_assert
(additional_length >= 0);
00816
00817
if
(_DBUS_UNLIKELY (additional_length > real->
structDBusRealString.html#o3
max_length
- real->
structDBusRealString.html#o1
len
))
00818
return
group__DBusMacros.html#ga3
FALSE
;
/* would overflow */
00819
00820
return
set_length (real,
00821                      real->
structDBusRealString.html#o1
len
+ additional_length);
00822 }
00823
00830
void
group__DBusString.html#ga20
00831
group__DBusString.html#ga20
_dbus_string_shorten
(
structDBusString.html
DBusString
*str,
00832
int
length_to_remove)
00833 {
00834
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
00835
group__DBusInternalsUtils.html#ga130
_dbus_assert
(length_to_remove >= 0);
00836
group__DBusInternalsUtils.html#ga130
_dbus_assert
(length_to_remove <= real->len);
00837
00838   set_length (real,
00839               real->
structDBusRealString.html#o1
len
- length_to_remove);
00840 }
00841
00852
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga21
00853
group__DBusString.html#ga21
_dbus_string_set_length
(
structDBusString.html
DBusString
*str,
00854
int
length)
00855 {
00856
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
00857
group__DBusInternalsUtils.html#ga130
_dbus_assert
(length >= 0);
00858
00859
return
set_length (real, length);
00860 }
00861
00862
static
group__DBusTypes.html#ga2
dbus_bool_t
00863 align_insert_point_then_open_gap (
structDBusString.html
DBusString
*str,
00864
int
*insert_at_p,
00865
int
alignment,
00866
int
gap_size)
00867 {
00868
unsigned
long
new_len;
/* ulong to avoid _DBUS_ALIGN_VALUE overflow */
00869
unsigned
long
gap_pos;
00870
int
insert_at;
00871
int
delta;
00872
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
00873
group__DBusInternalsUtils.html#ga130
_dbus_assert
(alignment >= 1);
00874
group__DBusInternalsUtils.html#ga130
_dbus_assert
(alignment <= 8);
/* it has to be a bug if > 8 */
00875
00876   insert_at = *insert_at_p;
00877
00878
group__DBusInternalsUtils.html#ga130
_dbus_assert
(insert_at <= real->len);
00879
00880   gap_pos = _DBUS_ALIGN_VALUE (insert_at, alignment);
00881   new_len = real->
structDBusRealString.html#o1
len
+ (gap_pos - insert_at) + gap_size;
00882
00883
if
(_DBUS_UNLIKELY (new_len > (
unsigned
long
) real->
structDBusRealString.html#o3
max_length
))
00884
return
group__DBusMacros.html#ga3
FALSE
;
00885
00886   delta = new_len - real->
structDBusRealString.html#o1
len
;
00887
group__DBusInternalsUtils.html#ga130
_dbus_assert
(delta >= 0);
00888
00889
if
(delta == 0)
/* only happens if gap_size == 0 and insert_at is aligned already */
00890     {
00891
group__DBusInternalsUtils.html#ga130
_dbus_assert
(((
unsigned
long
) *insert_at_p) == gap_pos);
00892
return
group__DBusMacros.html#ga2
TRUE
;
00893     }
00894
00895
if
(_DBUS_UNLIKELY (!open_gap (new_len - real->
structDBusRealString.html#o1
len
,
00896                                  real, insert_at)))
00897
return
group__DBusMacros.html#ga3
FALSE
;
00898
00899
/* nul the padding if we had to add any padding */
00900
if
(gap_size < delta)
00901     {
00902       memset (&real->
structDBusRealString.html#o0
str
[insert_at],
'\0'
,
00903               gap_pos - insert_at);
00904     }
00905
00906   *insert_at_p = gap_pos;
00907
00908
return
group__DBusMacros.html#ga2
TRUE
;
00909 }
00910
00911
static
group__DBusTypes.html#ga2
dbus_bool_t
00912 align_length_then_lengthen (
structDBusString.html
DBusString
*str,
00913
int
alignment,
00914
int
then_lengthen_by)
00915 {
00916
int
insert_at;
00917
00918   insert_at = _dbus_string_get_length (str);
00919
00920
return
align_insert_point_then_open_gap (str,
00921                                            &insert_at,
00922                                            alignment, then_lengthen_by);
00923 }
00924
00933
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga24
00934
group__DBusString.html#ga24
_dbus_string_align_length
(
structDBusString.html
DBusString
*str,
00935
int
alignment)
00936 {
00937
return
align_length_then_lengthen (str, alignment, 0);
00938 }
00939
00949
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga25
00950
group__DBusString.html#ga25
_dbus_string_alloc_space
(
structDBusString.html
DBusString
*str,
00951
int
extra_bytes)
00952 {
00953
if
(!
group__DBusString.html#ga19
_dbus_string_lengthen
(str, extra_bytes))
00954
return
group__DBusMacros.html#ga3
FALSE
;
00955
group__DBusString.html#ga20
_dbus_string_shorten
(str, extra_bytes);
00956
00957
return
group__DBusMacros.html#ga2
TRUE
;
00958 }
00959
00960
static
group__DBusTypes.html#ga2
dbus_bool_t
00961 append (
structDBusRealString.html
DBusRealString
*real,
00962
const
char
*buffer,
00963
int
buffer_len)
00964 {
00965
if
(buffer_len == 0)
00966
return
group__DBusMacros.html#ga2
TRUE
;
00967
00968
if
(!
group__DBusString.html#ga19
_dbus_string_lengthen
((
structDBusString.html
DBusString
*)real, buffer_len))
00969
return
group__DBusMacros.html#ga3
FALSE
;
00970
00971   memcpy (real->str + (real->len - buffer_len),
00972           buffer,
00973           buffer_len);
00974
00975
return
group__DBusMacros.html#ga2
TRUE
;
00976 }
00977
00985
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga27
00986
group__DBusString.html#ga27
_dbus_string_append
(
structDBusString.html
DBusString
*str,
00987
const
char
*buffer)
00988 {
00989
unsigned
long
buffer_len;
00990
00991
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
00992
group__DBusInternalsUtils.html#ga130
_dbus_assert
(buffer !=
group__DBusMacros.html#ga4
NULL
);
00993
00994   buffer_len = strlen (buffer);
00995
if
(buffer_len > (
unsigned
long
) real->
structDBusRealString.html#o3
max_length
)
00996
return
group__DBusMacros.html#ga3
FALSE
;
00997
00998
return
append (real, buffer, buffer_len);
00999 }
01000
group__DBusString.html#ga64
01002
#define ASSIGN_2_OCTETS(p, octets) \
01003
*((dbus_uint16_t*)(p)) = *((dbus_uint16_t*)(octets));
01004
group__DBusString.html#ga65
01006
#define ASSIGN_4_OCTETS(p, octets) \
01007
*((dbus_uint32_t*)(p)) = *((dbus_uint32_t*)(octets));
01008
01009
#ifdef DBUS_HAVE_INT64
01010
group__DBusString.html#ga66
01011
#define ASSIGN_8_OCTETS(p, octets) \
01012
*((dbus_uint64_t*)(p)) = *((dbus_uint64_t*)(octets));
01013
#else
01014
01015
#define ASSIGN_8_OCTETS(p, octets)              \
01016
do {                                            \
01017
unsigned char *b;                             \
01018
\
01019
b = p;                                        \
01020
\
01021
*b++ = octets[0];                             \
01022
*b++ = octets[1];                             \
01023
*b++ = octets[2];                             \
01024
*b++ = octets[3];                             \
01025
*b++ = octets[4];                             \
01026
*b++ = octets[5];                             \
01027
*b++ = octets[6];                             \
01028
*b++ = octets[7];                             \
01029
_dbus_assert (b == p + 8);                    \
01030
} while (0)
01031
#endif
/* DBUS_HAVE_INT64 */
01032
01033
#ifdef DBUS_BUILD_TESTS
01034
01042
group__DBusTypes.html#ga2
dbus_bool_t
01043 _dbus_string_append_4_aligned (
structDBusString.html
DBusString
*str,
01044
const
unsigned
char
octets[4])
01045 {
01046
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
01047
01048
if
(!align_length_then_lengthen (str, 4, 4))
01049
return
group__DBusMacros.html#ga3
FALSE
;
01050
01051
group__DBusString.html#ga65
ASSIGN_4_OCTETS
(real->
structDBusRealString.html#o0
str
+ (real->
structDBusRealString.html#o1
len
- 4), octets);
01052
01053
return
group__DBusMacros.html#ga2
TRUE
;
01054 }
01055
#endif
/* DBUS_BUILD_TESTS */
01056
01057
#ifdef DBUS_BUILD_TESTS
01058
01066
group__DBusTypes.html#ga2
dbus_bool_t
01067 _dbus_string_append_8_aligned (
structDBusString.html
DBusString
*str,
01068
const
unsigned
char
octets[8])
01069 {
01070
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
01071
01072
if
(!align_length_then_lengthen (str, 8, 8))
01073
return
group__DBusMacros.html#ga3
FALSE
;
01074
01075
group__DBusString.html#ga66
ASSIGN_8_OCTETS
(real->
structDBusRealString.html#o0
str
+ (real->
structDBusRealString.html#o1
len
- 8), octets);
01076
01077
return
group__DBusMacros.html#ga2
TRUE
;
01078 }
01079
#endif
/* DBUS_BUILD_TESTS */
01080
01090
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga28
01091
group__DBusString.html#ga28
_dbus_string_insert_2_aligned
(
structDBusString.html
DBusString
*str,
01092
int
insert_at,
01093
const
unsigned
char
octets[4])
01094 {
01095
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
01096
01097
if
(!align_insert_point_then_open_gap (str, &insert_at, 2, 2))
01098
return
group__DBusMacros.html#ga3
FALSE
;
01099
01100
group__DBusString.html#ga64
ASSIGN_2_OCTETS
(real->
structDBusRealString.html#o0
str
+ insert_at, octets);
01101
01102
return
group__DBusMacros.html#ga2
TRUE
;
01103 }
01104
01114
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga29
01115
group__DBusString.html#ga29
_dbus_string_insert_4_aligned
(
structDBusString.html
DBusString
*str,
01116
int
insert_at,
01117
const
unsigned
char
octets[4])
01118 {
01119
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
01120
01121
if
(!align_insert_point_then_open_gap (str, &insert_at, 4, 4))
01122
return
group__DBusMacros.html#ga3
FALSE
;
01123
01124
group__DBusString.html#ga65
ASSIGN_4_OCTETS
(real->
structDBusRealString.html#o0
str
+ insert_at, octets);
01125
01126
return
group__DBusMacros.html#ga2
TRUE
;
01127 }
01128
01138
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga30
01139
group__DBusString.html#ga30
_dbus_string_insert_8_aligned
(
structDBusString.html
DBusString
*str,
01140
int
insert_at,
01141
const
unsigned
char
octets[8])
01142 {
01143
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
01144
01145
if
(!align_insert_point_then_open_gap (str, &insert_at, 8, 8))
01146
return
group__DBusMacros.html#ga3
FALSE
;
01147
01148
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_DBUS_ALIGN_VALUE (insert_at, 8) == (
unsigned
) insert_at);
01149
01150
group__DBusString.html#ga66
ASSIGN_8_OCTETS
(real->
structDBusRealString.html#o0
str
+ insert_at, octets);
01151
01152
return
group__DBusMacros.html#ga2
TRUE
;
01153 }
01154
01155
01166
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga31
01167
group__DBusString.html#ga31
_dbus_string_insert_alignment
(
structDBusString.html
DBusString
*str,
01168
int
*insert_at,
01169
int
alignment)
01170 {
01171
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
01172
01173
if
(!align_insert_point_then_open_gap (str, insert_at, alignment, 0))
01174
return
group__DBusMacros.html#ga3
FALSE
;
01175
01176
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_DBUS_ALIGN_VALUE (*insert_at, alignment) == (
unsigned
) *insert_at);
01177
01178
return
group__DBusMacros.html#ga2
TRUE
;
01179 }
01180
01190
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga32
01191
group__DBusString.html#ga32
_dbus_string_append_printf_valist
(
structDBusString.html
DBusString
*str,
01192
const
char
*format,
01193                                     va_list            args)
01194 {
01195
int
len;
01196
char
c;
01197   va_list args_copy;
01198
01199
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
01200
01201   DBUS_VA_COPY (args_copy, args);
01202
01203
/* Measure the message length without terminating nul */
01204   len = vsnprintf (&c, 1, format, args);
01205
01206
if
(!
group__DBusString.html#ga19
_dbus_string_lengthen
(str, len))
01207     {
01208
/* don't leak the copy */
01209       va_end (args_copy);
01210
return
group__DBusMacros.html#ga3
FALSE
;
01211     }
01212
01213   vsprintf ((
char
*) (real->
structDBusRealString.html#o0
str
+ (real->
structDBusRealString.html#o1
len
- len)),
01214             format, args_copy);
01215
01216   va_end (args_copy);
01217
01218
return
group__DBusMacros.html#ga2
TRUE
;
01219 }
01220
01229
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga33
01230
group__DBusString.html#ga33
_dbus_string_append_printf
(
structDBusString.html
DBusString
*str,
01231
const
char
*format,
01232                             ...)
01233 {
01234   va_list args;
01235
group__DBusTypes.html#ga2
dbus_bool_t
retval;
01236
01237   va_start (args, format);
01238   retval =
group__DBusString.html#ga32
_dbus_string_append_printf_valist
(str, format, args);
01239   va_end (args);
01240
01241
return
retval;
01242 }
01243
01252
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga34
01253
group__DBusString.html#ga34
_dbus_string_append_len
(
structDBusString.html
DBusString
*str,
01254
const
char
*buffer,
01255
int
len)
01256 {
01257
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
01258
group__DBusInternalsUtils.html#ga130
_dbus_assert
(buffer !=
group__DBusMacros.html#ga4
NULL
);
01259
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len >= 0);
01260
01261
return
append (real, buffer, len);
01262 }
01263
01272
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga35
01273
group__DBusString.html#ga35
_dbus_string_append_byte
(
structDBusString.html
DBusString
*str,
01274
unsigned
char
byte)
01275 {
01276
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
01277
01278
if
(!set_length (real, real->
structDBusRealString.html#o1
len
+ 1))
01279
return
group__DBusMacros.html#ga3
FALSE
;
01280
01281   real->str[real->len-1] = byte;
01282
01283
return
group__DBusMacros.html#ga2
TRUE
;
01284 }
01285
01286
#ifdef DBUS_BUILD_TESTS
01287
01294
group__DBusTypes.html#ga2
dbus_bool_t
01295 _dbus_string_append_unichar (
structDBusString.html
DBusString
*str,
01296                              dbus_unichar_t ch)
01297 {
01298
int
len;
01299
int
first;
01300
int
i;
01301
unsigned
char
*out;
01302
01303
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
01304
01305
/* this code is from GLib but is pretty standard I think */
01306
01307   len = 0;
01308
01309
if
(ch < 0x80)
01310     {
01311       first = 0;
01312       len = 1;
01313     }
01314
else
if
(ch < 0x800)
01315     {
01316       first = 0xc0;
01317       len = 2;
01318     }
01319
else
if
(ch < 0x10000)
01320     {
01321       first = 0xe0;
01322       len = 3;
01323     }
01324
else
if
(ch < 0x200000)
01325     {
01326       first = 0xf0;
01327       len = 4;
01328     }
01329
else
if
(ch < 0x4000000)
01330     {
01331       first = 0xf8;
01332       len = 5;
01333     }
01334
else
01335     {
01336       first = 0xfc;
01337       len = 6;
01338     }
01339
01340
if
(len > (real->
structDBusRealString.html#o3
max_length
- real->
structDBusRealString.html#o1
len
))
01341
return
group__DBusMacros.html#ga3
FALSE
;
/* real->len + len would overflow */
01342
01343
if
(!set_length (real, real->
structDBusRealString.html#o1
len
+ len))
01344
return
group__DBusMacros.html#ga3
FALSE
;
01345
01346   out = real->str + (real->len - len);
01347
01348
for
(i = len - 1; i > 0; --i)
01349     {
01350       out[i] = (ch & 0x3f) | 0x80;
01351       ch >>= 6;
01352     }
01353   out[0] = ch | first;
01354
01355
return
group__DBusMacros.html#ga2
TRUE
;
01356 }
01357
#endif
/* DBUS_BUILD_TESTS */
01358
01359
static
void
01360
delete
(
structDBusRealString.html
DBusRealString
*real,
01361
int
start,
01362
int
len)
01363 {
01364
if
(len == 0)
01365
return
;
01366
01367   memmove (real->
structDBusRealString.html#o0
str
+ start, real->
structDBusRealString.html#o0
str
+ start + len, real->
structDBusRealString.html#o1
len
- (start + len));
01368   real->
structDBusRealString.html#o1
len
-= len;
01369   real->
structDBusRealString.html#o0
str
[real->
structDBusRealString.html#o1
len
] =
'\0'
;
01370 }
01371
01381
void
group__DBusString.html#ga37
01382
group__DBusString.html#ga37
_dbus_string_delete
(
structDBusString.html
DBusString
*str,
01383
int
start,
01384
int
len)
01385 {
01386
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
01387
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start >= 0);
01388
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len >= 0);
01389
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real->len);
01390
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len <= real->len - start);
01391
01392
delete
(real, start, len);
01393 }
01394
01395
static
group__DBusTypes.html#ga2
dbus_bool_t
01396 copy (
structDBusRealString.html
DBusRealString
*source,
01397
int
start,
01398
int
len,
01399
structDBusRealString.html
DBusRealString
*dest,
01400
int
insert_at)
01401 {
01402
if
(len == 0)
01403
return
group__DBusMacros.html#ga2
TRUE
;
01404
01405
if
(!open_gap (len, dest, insert_at))
01406
return
group__DBusMacros.html#ga3
FALSE
;
01407
01408   memmove (dest->
structDBusRealString.html#o0
str
+ insert_at,
01409            source->
structDBusRealString.html#o0
str
+ start,
01410            len);
01411
01412
return
group__DBusMacros.html#ga2
TRUE
;
01413 }
01414
group__DBusString.html#ga67
01424
#define DBUS_STRING_COPY_PREAMBLE(source, start, dest, insert_at)       \
01425
DBusRealString *real_source = (DBusRealString*) source;               \
01426
DBusRealString *real_dest = (DBusRealString*) dest;                   \
01427
_dbus_assert ((source) != (dest));                                    \
01428
DBUS_GENERIC_STRING_PREAMBLE (real_source);                           \
01429
DBUS_GENERIC_STRING_PREAMBLE (real_dest);                             \
01430
_dbus_assert (!real_dest->constant);                                  \
01431
_dbus_assert (!real_dest->locked);                                    \
01432
_dbus_assert ((start) >= 0);                                          \
01433
_dbus_assert ((start) <= real_source->len);                           \
01434
_dbus_assert ((insert_at) >= 0);                                      \
01435
_dbus_assert ((insert_at) <= real_dest->len)
01436
01447
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga39
01448
group__DBusString.html#ga39
_dbus_string_move
(
structDBusString.html
DBusString
*source,
01449
int
start,
01450
structDBusString.html
DBusString
*dest,
01451
int
insert_at)
01452 {
01453
structDBusRealString.html
DBusRealString
*real_source = (
structDBusRealString.html
DBusRealString
*) source;
01454
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real_source->len);
01455
01456
return
group__DBusString.html#ga41
_dbus_string_move_len
(source, start,
01457                                 real_source->
structDBusRealString.html#o1
len
- start,
01458                                 dest, insert_at);
01459 }
01460
01471
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga40
01472
group__DBusString.html#ga40
_dbus_string_copy
(
const
structDBusString.html
DBusString
*source,
01473
int
start,
01474
structDBusString.html
DBusString
*dest,
01475
int
insert_at)
01476 {
01477
group__DBusString.html#ga67
DBUS_STRING_COPY_PREAMBLE
(source, start, dest, insert_at);
01478
01479
return
copy (real_source, start,
01480                real_source->len - start,
01481                real_dest,
01482                insert_at);
01483 }
01484
01499
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga41
01500
group__DBusString.html#ga41
_dbus_string_move_len
(
structDBusString.html
DBusString
*source,
01501
int
start,
01502
int
len,
01503
structDBusString.html
DBusString
*dest,
01504
int
insert_at)
01505
01506 {
01507
group__DBusString.html#ga67
DBUS_STRING_COPY_PREAMBLE
(source, start, dest, insert_at);
01508
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len >= 0);
01509
group__DBusInternalsUtils.html#ga130
_dbus_assert
((start + len) <= real_source->len);
01510
01511
01512
if
(len == 0)
01513     {
01514
return
group__DBusMacros.html#ga2
TRUE
;
01515     }
01516
else
if
(start == 0 &&
01517            len == real_source->len &&
01518            real_dest->len == 0)
01519     {
01520
/* Short-circuit moving an entire existing string to an empty string
01521
* by just swapping the buffers.
01522
*/
01523
/* we assume ->constant doesn't matter as you can't have
01524
* a constant string involved in a move.
01525
*/
01526
#define ASSIGN_DATA(a, b) do {                  \
01527
(a)->str = (b)->str;                    \
01528
(a)->len = (b)->len;                    \
01529
(a)->allocated = (b)->allocated;        \
01530
(a)->align_offset = (b)->align_offset;  \
01531
} while (0)
01532
01533
structDBusRealString.html
DBusRealString
tmp;
01534
01535       ASSIGN_DATA (&tmp, real_source);
01536       ASSIGN_DATA (real_source, real_dest);
01537       ASSIGN_DATA (real_dest, &tmp);
01538
01539
return
group__DBusMacros.html#ga2
TRUE
;
01540     }
01541
else
01542     {
01543
if
(!copy (real_source, start, len,
01544                  real_dest,
01545                  insert_at))
01546
return
group__DBusMacros.html#ga3
FALSE
;
01547
01548
delete
(real_source, start,
01549               len);
01550
01551
return
group__DBusMacros.html#ga2
TRUE
;
01552     }
01553 }
01554
01566
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga42
01567
group__DBusString.html#ga42
_dbus_string_copy_len
(
const
structDBusString.html
DBusString
*source,
01568
int
start,
01569
int
len,
01570
structDBusString.html
DBusString
*dest,
01571
int
insert_at)
01572 {
01573
group__DBusString.html#ga67
DBUS_STRING_COPY_PREAMBLE
(source, start, dest, insert_at);
01574
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len >= 0);
01575
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real_source->len);
01576
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len <= real_source->len - start);
01577
01578
return
copy (real_source, start, len,
01579                real_dest,
01580                insert_at);
01581 }
01582
01604
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga43
01605
group__DBusString.html#ga43
_dbus_string_replace_len
(
const
structDBusString.html
DBusString
*source,
01606
int
start,
01607
int
len,
01608
structDBusString.html
DBusString
*dest,
01609
int
replace_at,
01610
int
replace_len)
01611 {
01612
group__DBusString.html#ga67
DBUS_STRING_COPY_PREAMBLE
(source, start, dest, replace_at);
01613
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len >= 0);
01614
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real_source->len);
01615
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len <= real_source->len - start);
01616
group__DBusInternalsUtils.html#ga130
_dbus_assert
(replace_at >= 0);
01617
group__DBusInternalsUtils.html#ga130
_dbus_assert
(replace_at <= real_dest->len);
01618
group__DBusInternalsUtils.html#ga130
_dbus_assert
(replace_len <= real_dest->len - replace_at);
01619
01620
if
(!copy (real_source, start, len,
01621              real_dest, replace_at))
01622
return
group__DBusMacros.html#ga3
FALSE
;
01623
01624
delete
(real_dest, replace_at + len, replace_len);
01625
01626
return
group__DBusMacros.html#ga2
TRUE
;
01627 }
01628
01629
/* Unicode macros and utf8_validate() from GLib Owen Taylor, Havoc
01630
* Pennington, and Tom Tromey are the authors and authorized relicense.
01631
*/
01632
group__DBusString.html#ga68
01638
#define UTF8_COMPUTE(Char, Mask, Len)                                         \
01639
if (Char < 128)                                                             \
01640
{                                                                         \
01641
Len = 1;                                                                \
01642
Mask = 0x7f;                                                            \
01643
}                                                                         \
01644
else if ((Char & 0xe0) == 0xc0)                                             \
01645
{                                                                         \
01646
Len = 2;                                                                \
01647
Mask = 0x1f;                                                            \
01648
}                                                                         \
01649
else if ((Char & 0xf0) == 0xe0)                                             \
01650
{                                                                         \
01651
Len = 3;                                                                \
01652
Mask = 0x0f;                                                            \
01653
}                                                                         \
01654
else if ((Char & 0xf8) == 0xf0)                                             \
01655
{                                                                         \
01656
Len = 4;                                                                \
01657
Mask = 0x07;                                                            \
01658
}                                                                         \
01659
else if ((Char & 0xfc) == 0xf8)                                             \
01660
{                                                                         \
01661
Len = 5;                                                                \
01662
Mask = 0x03;                                                            \
01663
}                                                                         \
01664
else if ((Char & 0xfe) == 0xfc)                                             \
01665
{                                                                         \
01666
Len = 6;                                                                \
01667
Mask = 0x01;                                                            \
01668
}                                                                         \
01669
else                                                                        \
01670
{                                                                         \
01671
Len = 0;                                                               \
01672
Mask = 0;                                                               \
01673
}
01674
group__DBusString.html#ga69
01679
#define UTF8_LENGTH(Char)              \
01680
((Char) < 0x80 ? 1 :                 \
01681
((Char) < 0x800 ? 2 :               \
01682
((Char) < 0x10000 ? 3 :            \
01683
((Char) < 0x200000 ? 4 :          \
01684
((Char) < 0x4000000 ? 5 : 6)))))
01685
group__DBusString.html#ga70
01695
#define UTF8_GET(Result, Chars, Count, Mask, Len)                             \
01696
(Result) = (Chars)[0] & (Mask);                                             \
01697
for ((Count) = 1; (Count) < (Len); ++(Count))                               \
01698
{                                                                         \
01699
if (((Chars)[(Count)] & 0xc0) != 0x80)                                  \
01700
{                                                                     \
01701
(Result) = -1;                                                      \
01702
break;                                                              \
01703
}                                                                     \
01704
(Result) <<= 6;                                                         \
01705
(Result) |= ((Chars)[(Count)] & 0x3f);                                  \
01706
}
01707
group__DBusString.html#ga71
01713
#define UNICODE_VALID(Char)                   \
01714
((Char) < 0x110000 &&                     \
01715
(((Char) & 0xFFFFF800) != 0xD800) &&     \
01716
((Char) < 0xFDD0 || (Char) > 0xFDEF) &&  \
01717
((Char) & 0xFFFF) != 0xFFFF)
01718
01719
#ifdef DBUS_BUILD_TESTS
01720
01730
void
01731 _dbus_string_get_unichar (
const
structDBusString.html
DBusString
*str,
01732
int
start,
01733                           dbus_unichar_t   *ch_return,
01734
int
*end_return)
01735 {
01736
int
i, mask, len;
01737   dbus_unichar_t result;
01738
unsigned
char
c;
01739
unsigned
char
*p;
01740
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
01741
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start >= 0);
01742
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real->len);
01743
01744
if
(ch_return)
01745     *ch_return = 0;
01746
if
(end_return)
01747     *end_return = real->
structDBusRealString.html#o1
len
;
01748
01749   mask = 0;
01750   p = real->
structDBusRealString.html#o0
str
+ start;
01751   c = *p;
01752
01753
group__DBusString.html#ga68
UTF8_COMPUTE
(c, mask, len);
01754
if
(len == 0)
01755
return
;
01756
group__DBusString.html#ga70
UTF8_GET
(result, p, i, mask, len);
01757
01758
if
(result == (dbus_unichar_t)-1)
01759
return
;
01760
01761
if
(ch_return)
01762     *ch_return = result;
01763
if
(end_return)
01764     *end_return = start + len;
01765 }
01766
#endif
/* DBUS_BUILD_TESTS */
01767
01782
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga44
01783
group__DBusString.html#ga44
_dbus_string_find
(
const
structDBusString.html
DBusString
*str,
01784
int
start,
01785
const
char
*substr,
01786
int
*found)
01787 {
01788
return
group__DBusString.html#ga45
_dbus_string_find_to
(str, start,
01789                                ((
const
structDBusRealString.html
DBusRealString
*)str)->len,
01790                                substr, found);
01791 }
01792
01809
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga45
01810
group__DBusString.html#ga45
_dbus_string_find_to
(
const
structDBusString.html
DBusString
*str,
01811
int
start,
01812
int
end,
01813
const
char
*substr,
01814
int
*found)
01815 {
01816
int
i;
01817
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
01818
group__DBusInternalsUtils.html#ga130
_dbus_assert
(substr !=
group__DBusMacros.html#ga4
NULL
);
01819
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real->len);
01820
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start >= 0);
01821
group__DBusInternalsUtils.html#ga130
_dbus_assert
(substr !=
group__DBusMacros.html#ga4
NULL
);
01822
group__DBusInternalsUtils.html#ga130
_dbus_assert
(end <= real->len);
01823
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= end);
01824
01825
/* we always "find" an empty string */
01826
if
(*substr ==
'\0'
)
01827     {
01828
if
(found)
01829         *found = start;
01830
return
group__DBusMacros.html#ga2
TRUE
;
01831     }
01832
01833   i = start;
01834
while
(i < end)
01835     {
01836
if
(real->
structDBusRealString.html#o0
str
[i] == substr[0])
01837         {
01838
int
j = i + 1;
01839
01840
while
(j < end)
01841             {
01842
if
(substr[j - i] ==
'\0'
)
01843
break
;
01844
else
if
(real->
structDBusRealString.html#o0
str
[j] != substr[j - i])
01845
break
;
01846
01847               ++j;
01848             }
01849
01850
if
(substr[j - i] ==
'\0'
)
01851             {
01852
if
(found)
01853                 *found = i;
01854
return
group__DBusMacros.html#ga2
TRUE
;
01855             }
01856         }
01857
01858       ++i;
01859     }
01860
01861
if
(found)
01862     *found = end;
01863
01864
return
group__DBusMacros.html#ga3
FALSE
;
01865 }
01866
01877
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga46
01878
group__DBusString.html#ga46
_dbus_string_find_blank
(
const
structDBusString.html
DBusString
*str,
01879
int
start,
01880
int
*found)
01881 {
01882
int
i;
01883
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
01884
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real->len);
01885
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start >= 0);
01886
01887   i = start;
01888
while
(i < real->len)
01889     {
01890
if
(real->
structDBusRealString.html#o0
str
[i] ==
' '
||
01891           real->
structDBusRealString.html#o0
str
[i] ==
'\t'
)
01892         {
01893
if
(found)
01894             *found = i;
01895
return
group__DBusMacros.html#ga2
TRUE
;
01896         }
01897
01898       ++i;
01899     }
01900
01901
if
(found)
01902     *found = real->
structDBusRealString.html#o1
len
;
01903
01904
return
group__DBusMacros.html#ga3
FALSE
;
01905 }
01906
01915
void
group__DBusString.html#ga47
01916
group__DBusString.html#ga47
_dbus_string_skip_blank
(
const
structDBusString.html
DBusString
*str,
01917
int
start,
01918
int
*end)
01919 {
01920
int
i;
01921
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
01922
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real->len);
01923
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start >= 0);
01924
01925   i = start;
01926
while
(i < real->len)
01927     {
01928
if
(!(real->
structDBusRealString.html#o0
str
[i] ==
' '
||
01929             real->
structDBusRealString.html#o0
str
[i] ==
'\t'
))
01930
break
;
01931
01932       ++i;
01933     }
01934
01935
group__DBusInternalsUtils.html#ga130
_dbus_assert
(i == real->
structDBusRealString.html#o1
len
|| !(real->
structDBusRealString.html#o0
str
[i] ==
' '
||
01936                                     real->
structDBusRealString.html#o0
str
[i] ==
'\t'
));
01937
01938
if
(end)
01939     *end = i;
01940 }
01941
01957
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga48
01958
group__DBusString.html#ga48
_dbus_string_pop_line
(
structDBusString.html
DBusString
*source,
01959
structDBusString.html
DBusString
*dest)
01960 {
01961
int
eol;
01962
group__DBusTypes.html#ga2
dbus_bool_t
have_newline;
01963
01964
group__DBusString.html#ga21
_dbus_string_set_length
(dest, 0);
01965
01966   eol = 0;
01967
if
(
group__DBusString.html#ga44
_dbus_string_find
(source, 0,
"\n"
, &eol))
01968     {
01969       have_newline =
group__DBusMacros.html#ga2
TRUE
;
01970       eol += 1;
/* include newline */
01971     }
01972
else
01973     {
01974       eol = _dbus_string_get_length (source);
01975       have_newline =
group__DBusMacros.html#ga3
FALSE
;
01976     }
01977
01978
if
(eol == 0)
01979
return
group__DBusMacros.html#ga3
FALSE
;
/* eof */
01980
01981
if
(!
group__DBusString.html#ga41
_dbus_string_move_len
(source, 0, eol,
01982                               dest, 0))
01983     {
01984
return
group__DBusMacros.html#ga3
FALSE
;
01985     }
01986
01987
/* dump the newline and the \r if we have one */
01988
if
(have_newline)
01989     {
01990
group__DBusTypes.html#ga2
dbus_bool_t
have_cr;
01991
01992
group__DBusInternalsUtils.html#ga130
_dbus_assert
(_dbus_string_get_length (dest) > 0);
01993
01994
if
(_dbus_string_get_length (dest) > 1 &&
01995           _dbus_string_get_byte (dest,
01996                                  _dbus_string_get_length (dest) - 2) ==
'\r'
)
01997         have_cr =
group__DBusMacros.html#ga2
TRUE
;
01998
else
01999         have_cr =
group__DBusMacros.html#ga3
FALSE
;
02000
02001
group__DBusString.html#ga21
_dbus_string_set_length
(dest,
02002                                _dbus_string_get_length (dest) -
02003                                (have_cr ? 2 : 1));
02004     }
02005
02006
return
group__DBusMacros.html#ga2
TRUE
;
02007 }
02008
02009
#ifdef DBUS_BUILD_TESTS
02010
02016
void
02017 _dbus_string_delete_first_word (
structDBusString.html
DBusString
*str)
02018 {
02019
int
i;
02020
02021
if
(
group__DBusString.html#ga46
_dbus_string_find_blank
(str, 0, &i))
02022
group__DBusString.html#ga47
_dbus_string_skip_blank
(str, i, &i);
02023
02024
group__DBusString.html#ga37
_dbus_string_delete
(str, 0, i);
02025 }
02026
#endif
02027
02028
#ifdef DBUS_BUILD_TESTS
02029
02034
void
02035 _dbus_string_delete_leading_blanks (
structDBusString.html
DBusString
*str)
02036 {
02037
int
i;
02038
02039
group__DBusString.html#ga47
_dbus_string_skip_blank
(str, 0, &i);
02040
02041
if
(i > 0)
02042
group__DBusString.html#ga37
_dbus_string_delete
(str, 0, i);
02043 }
02044
#endif
02045
02055
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga49
02056
group__DBusString.html#ga49
_dbus_string_equal
(
const
structDBusString.html
DBusString
*a,
02057
const
structDBusString.html
DBusString
*b)
02058 {
02059
const
unsigned
char
*ap;
02060
const
unsigned
char
*bp;
02061
const
unsigned
char
*a_end;
02062
const
structDBusRealString.html
DBusRealString
*real_a = (
const
structDBusRealString.html
DBusRealString
*) a;
02063
const
structDBusRealString.html
DBusRealString
*real_b = (
const
structDBusRealString.html
DBusRealString
*) b;
02064
group__DBusStringInternals.html#ga1
DBUS_GENERIC_STRING_PREAMBLE
(real_a);
02065
group__DBusStringInternals.html#ga1
DBUS_GENERIC_STRING_PREAMBLE
(real_b);
02066
02067
if
(real_a->
structDBusRealString.html#o1
len
!= real_b->
structDBusRealString.html#o1
len
)
02068
return
group__DBusMacros.html#ga3
FALSE
;
02069
02070   ap = real_a->
structDBusRealString.html#o0
str
;
02071   bp = real_b->
structDBusRealString.html#o0
str
;
02072   a_end = real_a->
structDBusRealString.html#o0
str
+ real_a->
structDBusRealString.html#o1
len
;
02073
while
(ap != a_end)
02074     {
02075
if
(*ap != *bp)
02076
return
group__DBusMacros.html#ga3
FALSE
;
02077
02078       ++ap;
02079       ++bp;
02080     }
02081
02082
return
group__DBusMacros.html#ga2
TRUE
;
02083 }
02084
02085
#ifdef DBUS_BUILD_TESTS
02086
02099
group__DBusTypes.html#ga2
dbus_bool_t
02100 _dbus_string_equal_len (
const
structDBusString.html
DBusString
*a,
02101
const
structDBusString.html
DBusString
*b,
02102
int
len)
02103 {
02104
const
unsigned
char
*ap;
02105
const
unsigned
char
*bp;
02106
const
unsigned
char
*a_end;
02107
const
structDBusRealString.html
DBusRealString
*real_a = (
const
structDBusRealString.html
DBusRealString
*) a;
02108
const
structDBusRealString.html
DBusRealString
*real_b = (
const
structDBusRealString.html
DBusRealString
*) b;
02109
group__DBusStringInternals.html#ga1
DBUS_GENERIC_STRING_PREAMBLE
(real_a);
02110
group__DBusStringInternals.html#ga1
DBUS_GENERIC_STRING_PREAMBLE
(real_b);
02111
02112
if
(real_a->
structDBusRealString.html#o1
len
!= real_b->
structDBusRealString.html#o1
len
&&
02113       (real_a->
structDBusRealString.html#o1
len
< len || real_b->
structDBusRealString.html#o1
len
< len))
02114
return
group__DBusMacros.html#ga3
FALSE
;
02115
02116   ap = real_a->
structDBusRealString.html#o0
str
;
02117   bp = real_b->
structDBusRealString.html#o0
str
;
02118   a_end = real_a->
structDBusRealString.html#o0
str
+ MIN (real_a->
structDBusRealString.html#o1
len
, len);
02119
while
(ap != a_end)
02120     {
02121
if
(*ap != *bp)
02122
return
group__DBusMacros.html#ga3
FALSE
;
02123
02124       ++ap;
02125       ++bp;
02126     }
02127
02128
return
group__DBusMacros.html#ga2
TRUE
;
02129 }
02130
#endif
/* DBUS_BUILD_TESTS */
02131
02148
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga50
02149
group__DBusString.html#ga50
_dbus_string_equal_substring
(
const
structDBusString.html
DBusString
*a,
02150
int
a_start,
02151
int
a_len,
02152
const
structDBusString.html
DBusString
*b,
02153
int
b_start)
02154 {
02155
const
unsigned
char
*ap;
02156
const
unsigned
char
*bp;
02157
const
unsigned
char
*a_end;
02158
const
structDBusRealString.html
DBusRealString
*real_a = (
const
structDBusRealString.html
DBusRealString
*) a;
02159
const
structDBusRealString.html
DBusRealString
*real_b = (
const
structDBusRealString.html
DBusRealString
*) b;
02160
group__DBusStringInternals.html#ga1
DBUS_GENERIC_STRING_PREAMBLE
(real_a);
02161
group__DBusStringInternals.html#ga1
DBUS_GENERIC_STRING_PREAMBLE
(real_b);
02162
group__DBusInternalsUtils.html#ga130
_dbus_assert
(a_start >= 0);
02163
group__DBusInternalsUtils.html#ga130
_dbus_assert
(a_len >= 0);
02164
group__DBusInternalsUtils.html#ga130
_dbus_assert
(a_start <= real_a->len);
02165
group__DBusInternalsUtils.html#ga130
_dbus_assert
(a_len <= real_a->len - a_start);
02166
group__DBusInternalsUtils.html#ga130
_dbus_assert
(b_start >= 0);
02167
group__DBusInternalsUtils.html#ga130
_dbus_assert
(b_start <= real_b->len);
02168
02169
if
(a_len > real_b->
structDBusRealString.html#o1
len
- b_start)
02170
return
group__DBusMacros.html#ga3
FALSE
;
02171
02172   ap = real_a->
structDBusRealString.html#o0
str
+ a_start;
02173   bp = real_b->
structDBusRealString.html#o0
str
+ b_start;
02174   a_end = ap + a_len;
02175
while
(ap != a_end)
02176     {
02177
if
(*ap != *bp)
02178
return
group__DBusMacros.html#ga3
FALSE
;
02179
02180       ++ap;
02181       ++bp;
02182     }
02183
02184
group__DBusInternalsUtils.html#ga130
_dbus_assert
(bp <= (real_b->
structDBusRealString.html#o0
str
+ real_b->
structDBusRealString.html#o1
len
));
02185
02186
return
group__DBusMacros.html#ga2
TRUE
;
02187 }
02188
02196
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga51
02197
group__DBusString.html#ga51
_dbus_string_equal_c_str
(
const
structDBusString.html
DBusString
*a,
02198
const
char
*c_str)
02199 {
02200
const
unsigned
char
*ap;
02201
const
unsigned
char
*bp;
02202
const
unsigned
char
*a_end;
02203
const
structDBusRealString.html
DBusRealString
*real_a = (
const
structDBusRealString.html
DBusRealString
*) a;
02204
group__DBusStringInternals.html#ga1
DBUS_GENERIC_STRING_PREAMBLE
(real_a);
02205
group__DBusInternalsUtils.html#ga130
_dbus_assert
(c_str !=
group__DBusMacros.html#ga4
NULL
);
02206
02207   ap = real_a->
structDBusRealString.html#o0
str
;
02208   bp = (
const
unsigned
char
*) c_str;
02209   a_end = real_a->
structDBusRealString.html#o0
str
+ real_a->
structDBusRealString.html#o1
len
;
02210
while
(ap != a_end && *bp)
02211     {
02212
if
(*ap != *bp)
02213
return
group__DBusMacros.html#ga3
FALSE
;
02214
02215       ++ap;
02216       ++bp;
02217     }
02218
02219
if
(ap != a_end || *bp)
02220
return
group__DBusMacros.html#ga3
FALSE
;
02221
02222
return
group__DBusMacros.html#ga2
TRUE
;
02223 }
02224
02225
#ifdef DBUS_BUILD_TESTS
02226
02233
group__DBusTypes.html#ga2
dbus_bool_t
02234 _dbus_string_starts_with_c_str (
const
structDBusString.html
DBusString
*a,
02235
const
char
*c_str)
02236 {
02237
const
unsigned
char
*ap;
02238
const
unsigned
char
*bp;
02239
const
unsigned
char
*a_end;
02240
const
structDBusRealString.html
DBusRealString
*real_a = (
const
structDBusRealString.html
DBusRealString
*) a;
02241
group__DBusStringInternals.html#ga1
DBUS_GENERIC_STRING_PREAMBLE
(real_a);
02242
group__DBusInternalsUtils.html#ga130
_dbus_assert
(c_str !=
group__DBusMacros.html#ga4
NULL
);
02243
02244   ap = real_a->
structDBusRealString.html#o0
str
;
02245   bp = (
const
unsigned
char
*) c_str;
02246   a_end = real_a->
structDBusRealString.html#o0
str
+ real_a->
structDBusRealString.html#o1
len
;
02247
while
(ap != a_end && *bp)
02248     {
02249
if
(*ap != *bp)
02250
return
group__DBusMacros.html#ga3
FALSE
;
02251
02252       ++ap;
02253       ++bp;
02254     }
02255
02256
if
(*bp ==
'\0'
)
02257
return
group__DBusMacros.html#ga2
TRUE
;
02258
else
02259
return
group__DBusMacros.html#ga3
FALSE
;
02260 }
02261
#endif
/* DBUS_BUILD_TESTS */
02262
02271
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga52
02272
group__DBusString.html#ga52
_dbus_string_append_byte_as_hex
(
structDBusString.html
DBusString
*str,
02273
int
byte)
02274 {
02275
const
char
hexdigits[16] = {
02276
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
02277
'a'
,
'b'
,
'c'
,
'd'
,
'e'
,
'f'
02278   };
02279
02280
if
(!
group__DBusString.html#ga35
_dbus_string_append_byte
(str,
02281                                  hexdigits[(byte >> 4)]))
02282
return
group__DBusMacros.html#ga3
FALSE
;
02283
02284
if
(!
group__DBusString.html#ga35
_dbus_string_append_byte
(str,
02285                                  hexdigits[(byte & 0x0f)]))
02286     {
02287
group__DBusString.html#ga21
_dbus_string_set_length
(str,
02288                                _dbus_string_get_length (str) - 1);
02289
return
group__DBusMacros.html#ga3
FALSE
;
02290     }
02291
02292
return
group__DBusMacros.html#ga2
TRUE
;
02293 }
02294
02305
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga53
02306
group__DBusString.html#ga53
_dbus_string_hex_encode
(
const
structDBusString.html
DBusString
*source,
02307
int
start,
02308
structDBusString.html
DBusString
*dest,
02309
int
insert_at)
02310 {
02311
structDBusString.html
DBusString
result;
02312
const
unsigned
char
*p;
02313
const
unsigned
char
*end;
02314
group__DBusTypes.html#ga2
dbus_bool_t
retval;
02315
02316
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= _dbus_string_get_length (source));
02317
02318
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&result))
02319
return
group__DBusMacros.html#ga3
FALSE
;
02320
02321   retval =
group__DBusMacros.html#ga3
FALSE
;
02322
02323   p = (
const
unsigned
char
*) _dbus_string_get_const_data (source);
02324   end = p + _dbus_string_get_length (source);
02325   p += start;
02326
02327
while
(p != end)
02328     {
02329
if
(!
group__DBusString.html#ga52
_dbus_string_append_byte_as_hex
(&result, *p))
02330
goto
out;
02331
02332       ++p;
02333     }
02334
02335
if
(!
group__DBusString.html#ga39
_dbus_string_move
(&result, 0, dest, insert_at))
02336
goto
out;
02337
02338   retval =
group__DBusMacros.html#ga2
TRUE
;
02339
02340  out:
02341
group__DBusString.html#ga9
_dbus_string_free
(&result);
02342
return
retval;
02343 }
02344
02355
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga54
02356
group__DBusString.html#ga54
_dbus_string_hex_decode
(
const
structDBusString.html
DBusString
*source,
02357
int
start,
02358
int
*end_return,
02359
structDBusString.html
DBusString
*dest,
02360
int
insert_at)
02361 {
02362
structDBusString.html
DBusString
result;
02363
const
unsigned
char
*p;
02364
const
unsigned
char
*end;
02365
group__DBusTypes.html#ga2
dbus_bool_t
retval;
02366
group__DBusTypes.html#ga2
dbus_bool_t
high_bits;
02367
02368
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= _dbus_string_get_length (source));
02369
02370
if
(!
group__DBusString.html#ga6
_dbus_string_init
(&result))
02371
return
group__DBusMacros.html#ga3
FALSE
;
02372
02373   retval =
group__DBusMacros.html#ga3
FALSE
;
02374
02375   high_bits =
group__DBusMacros.html#ga2
TRUE
;
02376   p = (
const
unsigned
char
*) _dbus_string_get_const_data (source);
02377   end = p + _dbus_string_get_length (source);
02378   p += start;
02379
02380
while
(p != end)
02381     {
02382
unsigned
int
val;
02383
02384
switch
(*p)
02385         {
02386
case
'0'
:
02387           val = 0;
02388
break
;
02389
case
'1'
:
02390           val = 1;
02391
break
;
02392
case
'2'
:
02393           val = 2;
02394
break
;
02395
case
'3'
:
02396           val = 3;
02397
break
;
02398
case
'4'
:
02399           val = 4;
02400
break
;
02401
case
'5'
:
02402           val = 5;
02403
break
;
02404
case
'6'
:
02405           val = 6;
02406
break
;
02407
case
'7'
:
02408           val = 7;
02409
break
;
02410
case
'8'
:
02411           val = 8;
02412
break
;
02413
case
'9'
:
02414           val = 9;
02415
break
;
02416
case
'a'
:
02417
case
'A'
:
02418           val = 10;
02419
break
;
02420
case
'b'
:
02421
case
'B'
:
02422           val = 11;
02423
break
;
02424
case
'c'
:
02425
case
'C'
:
02426           val = 12;
02427
break
;
02428
case
'd'
:
02429
case
'D'
:
02430           val = 13;
02431
break
;
02432
case
'e'
:
02433
case
'E'
:
02434           val = 14;
02435
break
;
02436
case
'f'
:
02437
case
'F'
:
02438           val = 15;
02439
break
;
02440
default
:
02441
goto
done;
02442         }
02443
02444
if
(high_bits)
02445         {
02446
if
(!
group__DBusString.html#ga35
_dbus_string_append_byte
(&result,
02447                                          val << 4))
02448
goto
out;
02449         }
02450
else
02451         {
02452
int
len;
02453
unsigned
char
b;
02454
02455           len = _dbus_string_get_length (&result);
02456
02457           b = _dbus_string_get_byte (&result, len - 1);
02458
02459           b |= val;
02460
02461           _dbus_string_set_byte (&result, len - 1, b);
02462         }
02463
02464       high_bits = !high_bits;
02465
02466       ++p;
02467     }
02468
02469  done:
02470
if
(!
group__DBusString.html#ga39
_dbus_string_move
(&result, 0, dest, insert_at))
02471
goto
out;
02472
02473
if
(end_return)
02474     *end_return = p - (
const
unsigned
char
*) _dbus_string_get_const_data (source);
02475
02476   retval =
group__DBusMacros.html#ga2
TRUE
;
02477
02478  out:
02479
group__DBusString.html#ga9
_dbus_string_free
(&result);
02480
return
retval;
02481 }
02482
02496
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga55
02497
group__DBusString.html#ga55
_dbus_string_validate_ascii
(
const
structDBusString.html
DBusString
*str,
02498
int
start,
02499
int
len)
02500 {
02501
const
unsigned
char
*s;
02502
const
unsigned
char
*end;
02503
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
02504
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start >= 0);
02505
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real->len);
02506
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len >= 0);
02507
02508
if
(len > real->
structDBusRealString.html#o1
len
- start)
02509
return
group__DBusMacros.html#ga3
FALSE
;
02510
02511   s = real->
structDBusRealString.html#o0
str
+ start;
02512   end = s + len;
02513
while
(s != end)
02514     {
02515
if
(_DBUS_UNLIKELY (!_DBUS_ISASCII (*s)))
02516
return
group__DBusMacros.html#ga3
FALSE
;
02517
02518       ++s;
02519     }
02520
02521
return
group__DBusMacros.html#ga2
TRUE
;
02522 }
02523
02539
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga56
02540
group__DBusString.html#ga56
_dbus_string_validate_utf8
(
const
structDBusString.html
DBusString
*str,
02541
int
start,
02542
int
len)
02543 {
02544
const
unsigned
char
*p;
02545
const
unsigned
char
*end;
02546
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
02547
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start >= 0);
02548
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real->len);
02549
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len >= 0);
02550
02551
/* we are doing _DBUS_UNLIKELY() here which might be
02552
* dubious in a generic library like GLib, but in D-BUS
02553
* we know we're validating messages and that it would
02554
* only be evil/broken apps that would have invalid
02555
* UTF-8. Also, this function seems to be a performance
02556
* bottleneck in profiles.
02557
*/
02558
02559
if
(_DBUS_UNLIKELY (len > real->
structDBusRealString.html#o1
len
- start))
02560
return
group__DBusMacros.html#ga3
FALSE
;
02561
02562   p = real->
structDBusRealString.html#o0
str
+ start;
02563   end = p + len;
02564
02565
while
(p < end)
02566     {
02567
int
i, mask, char_len;
02568       dbus_unichar_t result;
02569
02570
/* nul bytes considered invalid */
02571
if
(*p ==
'\0'
)
02572
break
;
02573
02574
/* Special-case ASCII; this makes us go a lot faster in
02575
* D-BUS profiles where we are typically validating
02576
* function names and such. We have to know that
02577
* all following checks will pass for ASCII though,
02578
* comments follow ...
02579
*/
02580
if
(*p < 128)
02581         {
02582           ++p;
02583
continue
;
02584         }
02585
02586
group__DBusString.html#ga68
UTF8_COMPUTE
(*p, mask, char_len);
02587
02588
if
(_DBUS_UNLIKELY (char_len == 0))
/* ASCII: char_len == 1 */
02589
break
;
02590
02591
/* check that the expected number of bytes exists in the remaining length */
02592
if
(_DBUS_UNLIKELY ((end - p) < char_len))
/* ASCII: p < end and char_len == 1 */
02593
break
;
02594
02595
group__DBusString.html#ga70
UTF8_GET
(result, p, i, mask, char_len);
02596
02597
/* Check for overlong UTF-8 */
02598
if
(_DBUS_UNLIKELY (
group__DBusString.html#ga69
UTF8_LENGTH
(result) != char_len))
/* ASCII: UTF8_LENGTH == 1 */
02599
break
;
02600
#if 0
02601
/* The UNICODE_VALID check below will catch this */
02602
if
(_DBUS_UNLIKELY (result == (dbus_unichar_t)-1))
/* ASCII: result = ascii value */
02603
break
;
02604
#endif
02605
02606
if
(_DBUS_UNLIKELY (!
group__DBusString.html#ga71
UNICODE_VALID
(result)))
/* ASCII: always valid */
02607
break
;
02608
02609
/* UNICODE_VALID should have caught it */
02610
group__DBusInternalsUtils.html#ga130
_dbus_assert
(result != (dbus_unichar_t)-1);
02611
02612       p += char_len;
02613     }
02614
02615
/* See that we covered the entire length if a length was
02616
* passed in
02617
*/
02618
if
(_DBUS_UNLIKELY (p != end))
02619
return
group__DBusMacros.html#ga3
FALSE
;
02620
else
02621
return
group__DBusMacros.html#ga2
TRUE
;
02622 }
02623
02637
group__DBusTypes.html#ga2
dbus_bool_t
group__DBusString.html#ga57
02638
group__DBusString.html#ga57
_dbus_string_validate_nul
(
const
structDBusString.html
DBusString
*str,
02639
int
start,
02640
int
len)
02641 {
02642
const
unsigned
char
*s;
02643
const
unsigned
char
*end;
02644
group__DBusStringInternals.html#ga4
DBUS_CONST_STRING_PREAMBLE
(str);
02645
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start >= 0);
02646
group__DBusInternalsUtils.html#ga130
_dbus_assert
(len >= 0);
02647
group__DBusInternalsUtils.html#ga130
_dbus_assert
(start <= real->len);
02648
02649
if
(len > real->
structDBusRealString.html#o1
len
- start)
02650
return
group__DBusMacros.html#ga3
FALSE
;
02651
02652   s = real->
structDBusRealString.html#o0
str
+ start;
02653   end = s + len;
02654
while
(s != end)
02655     {
02656
if
(_DBUS_UNLIKELY (*s !=
'\0'
))
02657
return
group__DBusMacros.html#ga3
FALSE
;
02658       ++s;
02659     }
02660
02661
return
group__DBusMacros.html#ga2
TRUE
;
02662 }
02663
02669
void
group__DBusString.html#ga58
02670
group__DBusString.html#ga58
_dbus_string_zero
(
structDBusString.html
DBusString
*str)
02671 {
02672
group__DBusStringInternals.html#ga2
DBUS_STRING_PREAMBLE
(str);
02673
02674   memset (real->
structDBusRealString.html#o0
str
- real->
structDBusRealString.html#o7
align_offset
,
'\0'
, real->
structDBusRealString.html#o2
allocated
);
02675 }
02678
/* tests are in dbus-string-util.c */
Generated on Tue Sep 13 01:28:07 2005 for D-BUS by
http://www.doxygen.org/index.html
doxygen
1.4.4
