31
|
1 |
/* -*- mode: C; c-file-style: "gnu" -*- */
|
|
2 |
/* dbus-string.h String utility class (internal to D-Bus implementation)
|
|
3 |
*
|
|
4 |
* Copyright (C) 2002, 2003 Red Hat, Inc.
|
|
5 |
* Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
|
|
6 |
* Licensed under the Academic Free License version 2.1
|
|
7 |
*
|
|
8 |
* This program is free software; you can redistribute it and/or modify
|
|
9 |
* it under the terms of the GNU General Public License as published by
|
|
10 |
* the Free Software Foundation; either version 2 of the License, or
|
|
11 |
* (at your option) any later version.
|
|
12 |
*
|
|
13 |
* This program is distributed in the hope that it will be useful,
|
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 |
* GNU General Public License for more details.
|
|
17 |
*
|
|
18 |
* You should have received a copy of the GNU General Public License
|
|
19 |
* along with this program; if not, write to the Free Software
|
|
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 |
*
|
|
22 |
*/
|
|
23 |
|
|
24 |
#ifndef DBUS_STRING_H
|
|
25 |
#define DBUS_STRING_H
|
|
26 |
|
|
27 |
#ifdef __SYMBIAN32__
|
|
28 |
#include "config.h"
|
|
29 |
#else
|
|
30 |
#include <config.h>
|
|
31 |
#endif
|
|
32 |
|
|
33 |
#ifdef __SYMBIAN32__
|
|
34 |
//these are not system headers in build time
|
|
35 |
#include <dbus/dbus-memory.h>
|
|
36 |
#include <dbus/dbus-types.h>
|
|
37 |
#include "dbus-sysdeps.h"
|
|
38 |
#else
|
|
39 |
#include <dbus/dbus-memory.h>
|
|
40 |
#include <dbus/dbus-types.h>
|
|
41 |
#include <dbus/dbus-sysdeps.h>
|
|
42 |
#endif
|
|
43 |
|
|
44 |
#include <stdarg.h>
|
|
45 |
|
|
46 |
DBUS_BEGIN_DECLS
|
|
47 |
|
|
48 |
/**
|
|
49 |
* DBusString object
|
|
50 |
*/
|
|
51 |
struct DBusString
|
|
52 |
{
|
|
53 |
const void *dummy1; /**< placeholder */
|
|
54 |
int dummy2; /**< placeholder */
|
|
55 |
int dummy3; /**< placeholder */
|
|
56 |
int dummy4; /**< placeholder */
|
|
57 |
unsigned int dummy5 : 1; /**< placeholder */
|
|
58 |
unsigned int dummy6 : 1; /**< placeholder */
|
|
59 |
unsigned int dummy7 : 1; /**< placeholder */
|
|
60 |
unsigned int dummy8 : 3; /**< placeholder */
|
|
61 |
};
|
|
62 |
|
|
63 |
#ifdef DBUS_DISABLE_ASSERT
|
|
64 |
/* Some simple inlining hacks; the current linker is not smart enough
|
|
65 |
* to inline non-exported symbols across files in the library.
|
|
66 |
* Note that these break type safety (due to the casts)
|
|
67 |
*/
|
|
68 |
#define _dbus_string_get_data(s) ((char*)(((DBusString*)(s))->dummy1))
|
|
69 |
#define _dbus_string_get_length(s) (((DBusString*)(s))->dummy2)
|
|
70 |
#define _dbus_string_set_byte(s, i, b) ((((unsigned char*)(((DBusString*)(s))->dummy1))[(i)]) = (unsigned char) (b))
|
|
71 |
#define _dbus_string_get_byte(s, i) (((const unsigned char*)(((DBusString*)(s))->dummy1))[(i)])
|
|
72 |
#define _dbus_string_get_const_data(s) ((const char*)(((DBusString*)(s))->dummy1))
|
|
73 |
#define _dbus_string_get_const_data_len(s,start,len) (((const char*)(((DBusString*)(s))->dummy1)) + (start))
|
|
74 |
#endif
|
|
75 |
|
|
76 |
#ifdef __SYMBIAN32__
|
|
77 |
IMPORT_C
|
|
78 |
#endif
|
|
79 |
dbus_bool_t _dbus_string_init (DBusString *str);
|
|
80 |
#ifdef __SYMBIAN32__
|
|
81 |
IMPORT_C
|
|
82 |
#endif
|
|
83 |
void _dbus_string_init_const (DBusString *str,
|
|
84 |
const char *value);
|
|
85 |
void _dbus_string_init_const_len (DBusString *str,
|
|
86 |
const char *value,
|
|
87 |
int len);
|
|
88 |
dbus_bool_t _dbus_string_init_preallocated (DBusString *str,
|
|
89 |
int allocate_size);
|
|
90 |
#ifdef __SYMBIAN32__
|
|
91 |
IMPORT_C
|
|
92 |
#endif
|
|
93 |
void _dbus_string_free (DBusString *str);
|
|
94 |
void _dbus_string_lock (DBusString *str);
|
|
95 |
#ifndef _dbus_string_get_data
|
|
96 |
char* _dbus_string_get_data (DBusString *str);
|
|
97 |
#endif /* _dbus_string_get_data */
|
|
98 |
#ifndef _dbus_string_get_const_data
|
|
99 |
const char* _dbus_string_get_const_data (const DBusString *str);
|
|
100 |
#endif /* _dbus_string_get_const_data */
|
|
101 |
char* _dbus_string_get_data_len (DBusString *str,
|
|
102 |
int start,
|
|
103 |
int len);
|
|
104 |
#ifndef _dbus_string_get_const_data_len
|
|
105 |
const char* _dbus_string_get_const_data_len (const DBusString *str,
|
|
106 |
int start,
|
|
107 |
int len);
|
|
108 |
#endif
|
|
109 |
#ifndef _dbus_string_set_byte
|
|
110 |
void _dbus_string_set_byte (DBusString *str,
|
|
111 |
int i,
|
|
112 |
unsigned char byte);
|
|
113 |
#endif
|
|
114 |
#ifndef _dbus_string_get_byte
|
|
115 |
unsigned char _dbus_string_get_byte (const DBusString *str,
|
|
116 |
int start);
|
|
117 |
#endif /* _dbus_string_get_byte */
|
|
118 |
#ifdef __SYMBIAN32__
|
|
119 |
IMPORT_C
|
|
120 |
#endif
|
|
121 |
dbus_bool_t _dbus_string_insert_bytes (DBusString *str,
|
|
122 |
int i,
|
|
123 |
int n_bytes,
|
|
124 |
unsigned char byte);
|
|
125 |
#ifdef __SYMBIAN32__
|
|
126 |
IMPORT_C
|
|
127 |
#endif
|
|
128 |
dbus_bool_t _dbus_string_insert_byte (DBusString *str,
|
|
129 |
int i,
|
|
130 |
unsigned char byte);
|
|
131 |
#ifdef __SYMBIAN32__
|
|
132 |
IMPORT_C
|
|
133 |
#endif
|
|
134 |
dbus_bool_t _dbus_string_steal_data (DBusString *str,
|
|
135 |
char **data_return);
|
|
136 |
dbus_bool_t _dbus_string_steal_data_len (DBusString *str,
|
|
137 |
char **data_return,
|
|
138 |
int start,
|
|
139 |
int len);
|
|
140 |
#ifdef __SYMBIAN32__
|
|
141 |
IMPORT_C
|
|
142 |
#endif
|
|
143 |
dbus_bool_t _dbus_string_copy_data (const DBusString *str,
|
|
144 |
char **data_return);
|
|
145 |
dbus_bool_t _dbus_string_copy_data_len (const DBusString *str,
|
|
146 |
char **data_return,
|
|
147 |
int start,
|
|
148 |
int len);
|
|
149 |
void _dbus_string_copy_to_buffer (const DBusString *str,
|
|
150 |
char *buffer,
|
|
151 |
int len);
|
|
152 |
#ifndef _dbus_string_get_length
|
|
153 |
int _dbus_string_get_length (const DBusString *str);
|
|
154 |
#endif /* !_dbus_string_get_length */
|
|
155 |
|
|
156 |
#ifdef __SYMBIAN32__
|
|
157 |
IMPORT_C
|
|
158 |
#endif
|
|
159 |
dbus_bool_t _dbus_string_lengthen (DBusString *str,
|
|
160 |
int additional_length);
|
|
161 |
#ifdef __SYMBIAN32__
|
|
162 |
IMPORT_C
|
|
163 |
#endif
|
|
164 |
void _dbus_string_shorten (DBusString *str,
|
|
165 |
int length_to_remove);
|
|
166 |
#ifdef __SYMBIAN32__
|
|
167 |
IMPORT_C
|
|
168 |
#endif
|
|
169 |
dbus_bool_t _dbus_string_set_length (DBusString *str,
|
|
170 |
int length);
|
|
171 |
dbus_bool_t _dbus_string_align_length (DBusString *str,
|
|
172 |
int alignment);
|
|
173 |
dbus_bool_t _dbus_string_alloc_space (DBusString *str,
|
|
174 |
int extra_bytes);
|
|
175 |
#ifdef __SYMBIAN32__
|
|
176 |
IMPORT_C
|
|
177 |
#endif
|
|
178 |
dbus_bool_t _dbus_string_append (DBusString *str,
|
|
179 |
const char *buffer);
|
|
180 |
#ifdef __SYMBIAN32__
|
|
181 |
IMPORT_C
|
|
182 |
#endif
|
|
183 |
dbus_bool_t _dbus_string_append_len (DBusString *str,
|
|
184 |
const char *buffer,
|
|
185 |
int len);
|
|
186 |
#ifdef __SYMBIAN32__
|
|
187 |
IMPORT_C
|
|
188 |
#endif
|
|
189 |
dbus_bool_t _dbus_string_append_int (DBusString *str,
|
|
190 |
long value);
|
|
191 |
dbus_bool_t _dbus_string_append_uint (DBusString *str,
|
|
192 |
unsigned long value);
|
|
193 |
#ifdef __SYMBIAN32__
|
|
194 |
IMPORT_C
|
|
195 |
#endif
|
|
196 |
dbus_bool_t _dbus_string_append_double (DBusString *str,
|
|
197 |
double value);
|
|
198 |
#ifdef __SYMBIAN32__
|
|
199 |
IMPORT_C
|
|
200 |
#endif
|
|
201 |
dbus_bool_t _dbus_string_append_byte (DBusString *str,
|
|
202 |
unsigned char byte);
|
|
203 |
#ifdef __SYMBIAN32__
|
|
204 |
IMPORT_C
|
|
205 |
#endif
|
|
206 |
dbus_bool_t _dbus_string_append_unichar (DBusString *str,
|
|
207 |
dbus_unichar_t ch);
|
|
208 |
dbus_bool_t _dbus_string_append_4_aligned (DBusString *str,
|
|
209 |
const unsigned char octets[4]);
|
|
210 |
dbus_bool_t _dbus_string_append_8_aligned (DBusString *str,
|
|
211 |
const unsigned char octets[8]);
|
|
212 |
#ifdef __SYMBIAN32__
|
|
213 |
IMPORT_C
|
|
214 |
#endif
|
|
215 |
dbus_bool_t _dbus_string_append_printf (DBusString *str,
|
|
216 |
const char *format,
|
|
217 |
...) _DBUS_GNUC_PRINTF (2, 3);
|
|
218 |
dbus_bool_t _dbus_string_append_printf_valist (DBusString *str,
|
|
219 |
const char *format,
|
|
220 |
va_list args);
|
|
221 |
dbus_bool_t _dbus_string_insert_2_aligned (DBusString *str,
|
|
222 |
int insert_at,
|
|
223 |
const unsigned char octets[2]);
|
|
224 |
dbus_bool_t _dbus_string_insert_4_aligned (DBusString *str,
|
|
225 |
int insert_at,
|
|
226 |
const unsigned char octets[4]);
|
|
227 |
dbus_bool_t _dbus_string_insert_8_aligned (DBusString *str,
|
|
228 |
int insert_at,
|
|
229 |
const unsigned char octets[8]);
|
|
230 |
dbus_bool_t _dbus_string_insert_alignment (DBusString *str,
|
|
231 |
int *insert_at,
|
|
232 |
int alignment);
|
|
233 |
#ifdef __SYMBIAN32__
|
|
234 |
IMPORT_C
|
|
235 |
#endif
|
|
236 |
void _dbus_string_delete (DBusString *str,
|
|
237 |
int start,
|
|
238 |
int len);
|
|
239 |
#ifdef __SYMBIAN32__
|
|
240 |
IMPORT_C
|
|
241 |
#endif
|
|
242 |
dbus_bool_t _dbus_string_move (DBusString *source,
|
|
243 |
int start,
|
|
244 |
DBusString *dest,
|
|
245 |
int insert_at);
|
|
246 |
#ifdef __SYMBIAN32__
|
|
247 |
IMPORT_C
|
|
248 |
#endif
|
|
249 |
dbus_bool_t _dbus_string_copy (const DBusString *source,
|
|
250 |
int start,
|
|
251 |
DBusString *dest,
|
|
252 |
int insert_at);
|
|
253 |
dbus_bool_t _dbus_string_move_len (DBusString *source,
|
|
254 |
int start,
|
|
255 |
int len,
|
|
256 |
DBusString *dest,
|
|
257 |
int insert_at);
|
|
258 |
#ifdef __SYMBIAN32__
|
|
259 |
IMPORT_C
|
|
260 |
#endif
|
|
261 |
dbus_bool_t _dbus_string_copy_len (const DBusString *source,
|
|
262 |
int start,
|
|
263 |
int len,
|
|
264 |
DBusString *dest,
|
|
265 |
int insert_at);
|
|
266 |
#ifdef __SYMBIAN32__
|
|
267 |
IMPORT_C
|
|
268 |
#endif
|
|
269 |
dbus_bool_t _dbus_string_replace_len (const DBusString *source,
|
|
270 |
int start,
|
|
271 |
int len,
|
|
272 |
DBusString *dest,
|
|
273 |
int replace_at,
|
|
274 |
int replace_len);
|
|
275 |
#ifdef __SYMBIAN32__
|
|
276 |
IMPORT_C
|
|
277 |
#endif
|
|
278 |
void _dbus_string_get_unichar (const DBusString *str,
|
|
279 |
int start,
|
|
280 |
dbus_unichar_t *ch_return,
|
|
281 |
int *end_return);
|
|
282 |
#ifdef __SYMBIAN32__
|
|
283 |
IMPORT_C
|
|
284 |
#endif
|
|
285 |
dbus_bool_t _dbus_string_parse_int (const DBusString *str,
|
|
286 |
int start,
|
|
287 |
long *value_return,
|
|
288 |
int *end_return);
|
|
289 |
#ifdef __SYMBIAN32__
|
|
290 |
IMPORT_C
|
|
291 |
#endif
|
|
292 |
dbus_bool_t _dbus_string_parse_uint (const DBusString *str,
|
|
293 |
int start,
|
|
294 |
unsigned long *value_return,
|
|
295 |
int *end_return);
|
|
296 |
#ifdef __SYMBIAN32__
|
|
297 |
IMPORT_C
|
|
298 |
#endif
|
|
299 |
dbus_bool_t _dbus_string_parse_double (const DBusString *str,
|
|
300 |
int start,
|
|
301 |
double *value,
|
|
302 |
int *end_return);
|
|
303 |
#ifdef __SYMBIAN32__
|
|
304 |
IMPORT_C
|
|
305 |
#endif
|
|
306 |
dbus_bool_t _dbus_string_find (const DBusString *str,
|
|
307 |
int start,
|
|
308 |
const char *substr,
|
|
309 |
int *found);
|
|
310 |
#ifdef __SYMBIAN32__
|
|
311 |
IMPORT_C
|
|
312 |
#endif
|
|
313 |
dbus_bool_t _dbus_string_find_eol (const DBusString *str,
|
|
314 |
int start,
|
|
315 |
int *found,
|
|
316 |
int *found_len);
|
|
317 |
|
|
318 |
#ifdef __SYMBIAN32__
|
|
319 |
IMPORT_C
|
|
320 |
#endif
|
|
321 |
dbus_bool_t _dbus_string_find_to (const DBusString *str,
|
|
322 |
int start,
|
|
323 |
int end,
|
|
324 |
const char *substr,
|
|
325 |
int *found);
|
|
326 |
#ifdef __SYMBIAN32__
|
|
327 |
IMPORT_C
|
|
328 |
#endif
|
|
329 |
dbus_bool_t _dbus_string_find_byte_backward (const DBusString *str,
|
|
330 |
int start,
|
|
331 |
unsigned char byte,
|
|
332 |
int *found);
|
|
333 |
dbus_bool_t _dbus_string_find_blank (const DBusString *str,
|
|
334 |
int start,
|
|
335 |
int *found);
|
|
336 |
void _dbus_string_skip_blank (const DBusString *str,
|
|
337 |
int start,
|
|
338 |
int *end);
|
|
339 |
#ifdef __SYMBIAN32__
|
|
340 |
IMPORT_C
|
|
341 |
#endif
|
|
342 |
void _dbus_string_skip_white (const DBusString *str,
|
|
343 |
int start,
|
|
344 |
int *end);
|
|
345 |
void _dbus_string_skip_white_reverse (const DBusString *str,
|
|
346 |
int end,
|
|
347 |
int *start);
|
|
348 |
#ifdef __SYMBIAN32__
|
|
349 |
IMPORT_C
|
|
350 |
#endif
|
|
351 |
dbus_bool_t _dbus_string_equal (const DBusString *a,
|
|
352 |
const DBusString *b);
|
|
353 |
#ifdef __SYMBIAN32__
|
|
354 |
IMPORT_C
|
|
355 |
#endif
|
|
356 |
dbus_bool_t _dbus_string_equal_c_str (const DBusString *a,
|
|
357 |
const char *c_str);
|
|
358 |
dbus_bool_t _dbus_string_equal_len (const DBusString *a,
|
|
359 |
const DBusString *b,
|
|
360 |
int len);
|
|
361 |
#ifdef __SYMBIAN32__
|
|
362 |
IMPORT_C
|
|
363 |
#endif
|
|
364 |
dbus_bool_t _dbus_string_equal_substring (const DBusString *a,
|
|
365 |
int a_start,
|
|
366 |
int a_len,
|
|
367 |
const DBusString *b,
|
|
368 |
int b_start);
|
|
369 |
dbus_bool_t _dbus_string_starts_with_c_str (const DBusString *a,
|
|
370 |
const char *c_str);
|
|
371 |
#ifdef __SYMBIAN32__
|
|
372 |
IMPORT_C
|
|
373 |
#endif
|
|
374 |
dbus_bool_t _dbus_string_ends_with_c_str (const DBusString *a,
|
|
375 |
const char *c_str);
|
|
376 |
dbus_bool_t _dbus_string_pop_line (DBusString *source,
|
|
377 |
DBusString *dest);
|
|
378 |
void _dbus_string_delete_first_word (DBusString *str);
|
|
379 |
void _dbus_string_delete_leading_blanks (DBusString *str);
|
|
380 |
void _dbus_string_chop_white (DBusString *str);
|
|
381 |
dbus_bool_t _dbus_string_append_byte_as_hex (DBusString *str,
|
|
382 |
int byte);
|
|
383 |
#ifdef __SYMBIAN32__
|
|
384 |
IMPORT_C
|
|
385 |
#endif
|
|
386 |
dbus_bool_t _dbus_string_hex_encode (const DBusString *source,
|
|
387 |
int start,
|
|
388 |
DBusString *dest,
|
|
389 |
int insert_at);
|
|
390 |
#ifdef __SYMBIAN32__
|
|
391 |
IMPORT_C
|
|
392 |
#endif
|
|
393 |
dbus_bool_t _dbus_string_hex_decode (const DBusString *source,
|
|
394 |
int start,
|
|
395 |
int *end_return,
|
|
396 |
DBusString *dest,
|
|
397 |
int insert_at);
|
|
398 |
dbus_bool_t _dbus_string_validate_ascii (const DBusString *str,
|
|
399 |
int start,
|
|
400 |
int len);
|
|
401 |
#ifdef __SYMBIAN32__
|
|
402 |
IMPORT_C
|
|
403 |
#endif
|
|
404 |
dbus_bool_t _dbus_string_validate_utf8 (const DBusString *str,
|
|
405 |
int start,
|
|
406 |
int len);
|
|
407 |
dbus_bool_t _dbus_string_validate_nul (const DBusString *str,
|
|
408 |
int start,
|
|
409 |
int len);
|
|
410 |
void _dbus_string_zero (DBusString *str);
|
|
411 |
|
|
412 |
|
|
413 |
/**
|
|
414 |
* We allocate 1 byte for nul termination, plus 7 bytes for possible
|
|
415 |
* align_offset, so we always need 8 bytes on top of the string's
|
|
416 |
* length to be in the allocated block.
|
|
417 |
*/
|
|
418 |
#define _DBUS_STRING_ALLOCATION_PADDING 8
|
|
419 |
|
|
420 |
/**
|
|
421 |
* Defines a static const variable with type #DBusString called "name"
|
|
422 |
* containing the given string literal.
|
|
423 |
*
|
|
424 |
* @param name the name of the variable
|
|
425 |
* @param str the string value
|
|
426 |
*/
|
|
427 |
#define _DBUS_STRING_DEFINE_STATIC(name, str) \
|
|
428 |
static const char _dbus_static_string_##name[] = str; \
|
|
429 |
static const DBusString name = { _dbus_static_string_##name, \
|
|
430 |
sizeof(_dbus_static_string_##name), \
|
|
431 |
sizeof(_dbus_static_string_##name) + \
|
|
432 |
_DBUS_STRING_ALLOCATION_PADDING, \
|
|
433 |
sizeof(_dbus_static_string_##name), \
|
|
434 |
TRUE, TRUE, FALSE, 0 }
|
|
435 |
|
|
436 |
DBUS_END_DECLS
|
|
437 |
|
|
438 |
#endif /* DBUS_STRING_H */
|