D-Bus: DBusString class

D-Bus 1.12.6

Macros | Functions
DBusString class
D-Bus secret internal implementation details

DBusString data structure for safer string handling. More...

Collaboration diagram for DBusString class:

## Macros
#define | ASSIGN_2_OCTETS(p, octets) *((dbus_uint16_t*)(p)) = *((dbus_uint16_t*)(octets));
| assign 2 bytes from one string to another
#define | ASSIGN_4_OCTETS(p, octets) *((dbus_uint32_t*)(p)) = *((dbus_uint32_t*)(octets));
| assign 4 bytes from one string to another
#define | ASSIGN_8_OCTETS(p, octets) *((dbus_uint64_t*)(p)) = *((dbus_uint64_t*)(octets));
| assign 8 bytes from one string to another
#define | DBUS_STRING_COPY_PREAMBLE(source, start, dest, insert_at)
| Checks assertions for two strings we're copying a segment between, and declares real_source/real_dest variables. More...
#define | UTF8_COMPUTE(Char, Mask, Len)
| computes length and mask of a unicode character More...
#define | UTF8_LENGTH(Char)
| computes length of a unicode character in UTF-8 More...
#define | UTF8_GET(Result, Chars, Count, Mask, Len)
| Gets a UTF-8 value. More...
#define | UNICODE_VALID(Char)
| Check whether a Unicode (5.2) char is in a valid range. More...

## Functions
dbus_bool_t | _dbus_string_ends_with_c_str (const DBusString *a, const char *c_str)
| Returns whether a string ends with the given suffix. More...
dbus_bool_t | _dbus_string_find_byte_backward (const DBusString *str, int start, unsigned char byte, int *found)
| Find the given byte scanning backward from the given start. More...
dbus_bool_t | _dbus_string_init_preallocated (DBusString *str, int allocate_size)
| Initializes a string that can be up to the given allocation size before it has to realloc. More...
dbus_bool_t | _dbus_string_init (DBusString *str)
| Initializes a string. More...
void | _dbus_string_init_const (DBusString *str, const char *value)
| Initializes a constant string. More...
void | _dbus_string_init_const_len (DBusString *str, const char *value, int len)
| Initializes a constant string with a length. More...
dbus_bool_t | _dbus_string_init_from_string (DBusString *str, const DBusString *from)
| Initializes a string from another string. More...
void | _dbus_string_free (DBusString *str)
| Frees a string created by _dbus_string_init(). More...
dbus_bool_t | _dbus_string_compact (DBusString *str, int max_waste)
| Compacts the string to avoid wasted memory. More...
char * | _dbus_string_get_data_len (DBusString *str, int start, int len)
| Gets a sub-portion of the raw character buffer from the string. More...
dbus_bool_t | _dbus_string_insert_bytes (DBusString *str, int i, int n_bytes, unsigned char byte)
| Inserts a number of bytes of a given value at the given position. More...
dbus_bool_t | _dbus_string_insert_byte (DBusString *str, int i, unsigned char byte)
| Inserts a single byte at the given position. More...
dbus_bool_t | _dbus_string_steal_data (DBusString *str, char **data_return)
| Like _dbus_string_get_data(), but removes the gotten data from the original string. More...
dbus_bool_t | _dbus_string_copy_data (const DBusString *str, char **data_return)
| Copies the data from the string into a char*. More...
void | _dbus_string_copy_to_buffer (const DBusString *str, char *buffer, int avail_len)
| Copies the contents of a DBusString into a different buffer. More...
void | _dbus_string_copy_to_buffer_with_nul (const DBusString *str, char *buffer, int avail_len)
| Copies the contents of a DBusString into a different buffer. More...
dbus_bool_t | _dbus_string_lengthen (DBusString *str, int additional_length)
| Makes a string longer by the given number of bytes. More...
void | _dbus_string_shorten (DBusString *str, int length_to_remove)
| Makes a string shorter by the given number of bytes. More...
dbus_bool_t | _dbus_string_set_length (DBusString *str, int length)
| Sets the length of a string. More...
dbus_bool_t | _dbus_string_align_length (DBusString *str, int alignment)
| Align the length of a string to a specific alignment (typically 4 or 8) by appending nul bytes to the string. More...
dbus_bool_t | _dbus_string_alloc_space (DBusString *str, int extra_bytes)
| Preallocate extra_bytes such that a future lengthening of the string by extra_bytes is guaranteed to succeed without an out of memory error. More...
dbus_bool_t | _dbus_string_append (DBusString *str, const char *buffer)
| Appends a nul-terminated C-style string to a DBusString. More...
dbus_bool_t | _dbus_string_insert_2_aligned (DBusString *str, int insert_at, const unsigned char octets[2])
| Inserts 2 bytes aligned on a 2 byte boundary with any alignment padding initialized to 0. More...
dbus_bool_t | _dbus_string_insert_4_aligned (DBusString *str, int insert_at, const unsigned char octets[4])
| Inserts 4 bytes aligned on a 4 byte boundary with any alignment padding initialized to 0. More...
dbus_bool_t | _dbus_string_insert_8_aligned (DBusString *str, int insert_at, const unsigned char octets[8])
| Inserts 8 bytes aligned on an 8 byte boundary with any alignment padding initialized to 0. More...
dbus_bool_t | _dbus_string_insert_alignment (DBusString *str, int *insert_at, int alignment)
| Inserts padding at *insert_at such to align it to the given boundary. More...
dbus_bool_t | _dbus_string_append_printf_valist (DBusString *str, const char *format, va_list args)
| Appends a printf-style formatted string to the DBusString. More...
dbus_bool_t | _dbus_string_append_printf (DBusString *str, const char *format,...)
| Appends a printf-style formatted string to the DBusString. More...
dbus_bool_t | _dbus_string_append_len (DBusString *str, const char *buffer, int len)
| Appends block of bytes with the given length to a DBusString. More...
dbus_bool_t | _dbus_string_append_byte (DBusString *str, unsigned char byte)
| Appends a single byte to the string, returning FALSE if not enough memory. More...
void | _dbus_string_delete (DBusString *str, int start, int len)
| Deletes a segment of a DBusString with length len starting at start. More...
dbus_bool_t | _dbus_string_move (DBusString *source, int start, DBusString *dest, int insert_at)
| Moves the end of one string into another string. More...
dbus_bool_t | _dbus_string_copy (const DBusString *source, int start, DBusString *dest, int insert_at)
| Like _dbus_string_move(), but does not delete the section of the source string that's copied to the dest string. More...
dbus_bool_t | _dbus_string_move_len (DBusString *source, int start, int len, DBusString *dest, int insert_at)
| Like _dbus_string_move(), but can move a segment from the middle of the source string. More...
dbus_bool_t | _dbus_string_copy_len (const DBusString *source, int start, int len, DBusString *dest, int insert_at)
| Like _dbus_string_copy(), but can copy a segment from the middle of the source string. More...
dbus_bool_t | _dbus_string_replace_len (const DBusString *source, int start, int len, DBusString *dest, int replace_at, int replace_len)
| Replaces a segment of dest string with a segment of source string. More...
dbus_bool_t | _dbus_string_split_on_byte (DBusString *source, unsigned char byte, DBusString *tail)
| Looks for the first occurance of a byte, deletes that byte, and moves everything after the byte to the beginning of a separate string. More...
dbus_bool_t | _dbus_string_find (const DBusString *str, int start, const char *substr, int *found)
| Finds the given substring in the string, returning TRUE and filling in the byte index where the substring was found, if it was found. More...
dbus_bool_t | _dbus_string_find_eol (const DBusString *str, int start, int *found, int *found_len)
| Finds end of line ("\r\n" or "\n") in the string, returning TRUE and filling in the byte index where the eol string was found, if it was found. More...
dbus_bool_t | _dbus_string_find_to (const DBusString *str, int start, int end, const char *substr, int *found)
| Finds the given substring in the string, up to a certain position, returning TRUE and filling in the byte index where the substring was found, if it was found. More...
dbus_bool_t | _dbus_string_find_blank (const DBusString *str, int start, int *found)
| Finds a blank (space or tab) in the string. More...
void | _dbus_string_skip_blank (const DBusString *str, int start, int *end)
| Skips blanks from start, storing the first non-blank in *end (blank is space or tab). More...
void | _dbus_string_skip_white (const DBusString *str, int start, int *end)
| Skips whitespace from start, storing the first non-whitespace in *end. More...
void | _dbus_string_skip_white_reverse (const DBusString *str, int end, int *start)
| Skips whitespace from end, storing the start index of the trailing whitespace in *start. More...
dbus_bool_t | _dbus_string_pop_line (DBusString *source, DBusString *dest)
| Assigns a newline-terminated or \r\n-terminated line from the front of the string to the given dest string. More...
void | _dbus_string_chop_white (DBusString *str)
| Deletes leading and trailing whitespace. More...
dbus_bool_t | _dbus_string_equal (const DBusString *a, const DBusString *b)
| Tests two DBusString for equality. More...
dbus_bool_t | _dbus_string_equal_len (const DBusString *a, const DBusString *b, int len)
| Tests two DBusString for equality up to the given length. More...
dbus_bool_t | _dbus_string_equal_substring (const DBusString *a, int a_start, int a_len, const DBusString *b, int b_start)
| Tests two sub-parts of two DBusString for equality. More...
dbus_bool_t | _dbus_string_equal_c_str (const DBusString *a, const char *c_str)
| Checks whether a string is equal to a C string. More...
dbus_bool_t | _dbus_string_starts_with_c_str (const DBusString *a, const char *c_str)
| Checks whether a string starts with the given C string. More...
dbus_bool_t | _dbus_string_append_byte_as_hex (DBusString *str, unsigned char byte)
| Appends a two-character hex digit to a string, where the hex digit has the value of the given byte. More...
dbus_bool_t | _dbus_string_hex_encode (const DBusString *source, int start, DBusString *dest, int insert_at)
| Encodes a string in hex, the way MD5 and SHA-1 are usually encoded. More...
dbus_bool_t | _dbus_string_hex_decode (const DBusString *source, int start, int *end_return, DBusString *dest, int insert_at)
| Decodes a string from hex encoding. More...
dbus_bool_t | _dbus_string_validate_ascii (const DBusString *str, int start, int len)
| Checks that the given range of the string is valid ASCII with no nul bytes. More...
void | _dbus_string_tolower_ascii (const DBusString *str, int start, int len)
| Converts the given range of the string to lower case. More...
void | _dbus_string_toupper_ascii (const DBusString *str, int start, int len)
| Converts the given range of the string to upper case. More...
dbus_bool_t | _dbus_string_validate_utf8 (const DBusString *str, int start, int len)
| Checks that the given range of the string is valid UTF-8. More...
dbus_bool_t | _dbus_string_validate_nul (const DBusString *str, int start, int len)
| Checks that the given range of the string is all nul bytes. More...
void | _dbus_string_zero (DBusString *str)
| Clears all allocated bytes in the string to zero. More...
dbus_bool_t | _dbus_string_get_dirname (const DBusString *filename, DBusString *dirname)
| Get the directory name from a complete filename. More...
dbus_bool_t | _dbus_unix_user_is_process_owner (dbus_uid_t uid)
| Checks to see if the UNIX user ID matches the UID of the process. More...
dbus_bool_t | _dbus_windows_user_is_process_owner (const char *windows_sid)
| Checks to see if the Windows user SID matches the owner of the process. More...
dbus_bool_t | _dbus_unix_user_is_at_console (dbus_uid_t uid, DBusError *error)
| Checks to see if the UNIX user ID is at the console. More...
dbus_bool_t | _dbus_parse_unix_group_from_config (const DBusString *groupname, dbus_gid_t *gid_p)
| Parse a UNIX group from the bus config file. More...
dbus_bool_t | _dbus_parse_unix_user_from_config (const DBusString *username, dbus_uid_t *uid_p)
| Parse a UNIX user from the bus config file. More...
dbus_bool_t | _dbus_unix_groups_from_uid (dbus_uid_t uid, dbus_gid_t **group_ids, int *n_group_ids)
| Gets all groups corresponding to the given UNIX user ID. More...
dbus_bool_t | _dbus_string_append_int (DBusString *str, long value)
| Appends an integer to a DBusString. More...
dbus_bool_t | _dbus_string_append_uint (DBusString *str, unsigned long value)
| Appends an unsigned integer to a DBusString. More...
dbus_bool_t | _dbus_string_parse_int (const DBusString *str, int start, long *value_return, int *end_return)
| Parses an integer contained in a DBusString. More...
dbus_bool_t | _dbus_string_parse_uint (const DBusString *str, int start, unsigned long *value_return, int *end_return)
| Parses an unsigned integer contained in a DBusString. More...

## Detailed Description

DBusString data structure for safer string handling.

Types and functions related to DBusString. DBusString is intended to be a string class that makes it hard to mess up security issues (and just in general harder to write buggy code). It should be used (or extended and then used) rather than the libc stuff in string.h. The string class is a bit inconvenient at spots because it handles out-of-memory failures and tries to be extra-robust.

A DBusString has a maximum length set at initialization time; this can be used to ensure that a buffer doesn't get too big. The _dbus_string_lengthen() method checks for overflow, and for max length being exceeded.

Try to avoid conversion to a plain C string, i.e. add methods on the string object instead, only convert to C string when passing things out to the public API. In particular, no sprintf, strcpy, strcat, any of that should be used. The GString feature of accepting negative numbers for "length of string" is also absent, because it could keep us from detecting bogus huge lengths. i.e. if we passed in some bogus huge length it would be taken to mean "current length of string" instead of "broken crack"

Todo:
  DBusString needs a lot of cleaning up; some of the API is no longer used, and the API is pretty inconsistent. In particular all the "append" APIs, especially those involving alignment but probably lots of them, are no longer used by the marshaling code which always does "inserts" now.

## Macro Definition Documentation

## ◆ DBUS_STRING_COPY_PREAMBLE

#define DBUS_STRING_COPY_PREAMBLE | ( |  | source,
|  |  | start,
|  |  | dest,
|  |  | insert_at
| ) |  |

Value:
DBusRealString *real_source = (DBusRealString*) source; \
DBusRealString *real_dest = (DBusRealString*) dest; \
_dbus_assert ((source) != (dest)); \
DBUS_GENERIC_STRING_PREAMBLE (real_source); \
DBUS_GENERIC_STRING_PREAMBLE (real_dest); \
_dbus_assert (!real_dest->constant); \
_dbus_assert (!real_dest->locked); \
_dbus_assert ((start) >= 0); \
_dbus_assert ((start) <= real_source->len); \
_dbus_assert ((insert_at) >= 0); \
_dbus_assert ((insert_at) <= real_dest->len)
DBusRealString
Internals of DBusString.
Definition: dbus-string-private.h:43
DBusRealString::len
int len
Length without nul.
Definition: dbus-string-private.h:46

Checks assertions for two strings we're copying a segment between, and declares real_source/real_dest variables.

Parameters

  source | the source string
  start | the starting offset
  dest | the dest string
  insert_at | where the copied segment is inserted

Definition at line 1235 of file dbus-string.c.

Referenced by _dbus_string_copy(), _dbus_string_copy_len(), _dbus_string_move_len(), and _dbus_string_replace_len().

## ◆ UNICODE_VALID

#define UNICODE_VALID | ( |  | Char | ) |

Value:
((Char) < 0x110000 && \
(((Char) & 0xFFFFF800) != 0xD800))

Check whether a Unicode (5.2) char is in a valid range.

The first check comes from the Unicode guarantee to never encode a point above 0x0010ffff, since UTF-16 couldn't represent it.

The second check covers surrogate pairs (category Cs).

Parameters

  Char | the character

Definition at line 1585 of file dbus-string.c.

Referenced by _dbus_string_validate_utf8().

## ◆ UTF8_COMPUTE

#define UTF8_COMPUTE | ( |  | Char,
|  |  | Mask,
|  |  | Len
| ) |  |

computes length and mask of a unicode character

Parameters

  Char | the char
  Mask | the mask variable to assign to
  Len | the length variable to assign to

Definition at line 1505 of file dbus-string.c.

Referenced by _dbus_string_validate_utf8().

## ◆ UTF8_GET

#define UTF8_GET | ( |  | Result,
|  |  | Chars,
|  |  | Count,
|  |  | Mask,
|  |  | Len
| ) |  |

Value:
(Result) = (Chars)[0] & (Mask); \
for ((Count) = 1; (Count) < (Len); ++(Count)) \
{ \
if (((Chars)[(Count)] & 0xc0) != 0x80) \
{ \
(Result) = -1; \
break; \
} \
(Result) <<= 6; \
(Result) |= ((Chars)[(Count)] & 0x3f); \
}

Gets a UTF-8 value.

Parameters

  Result | variable for extracted unicode char.
  Chars | the bytes to decode
  Count | counter variable
  Mask | mask for this char
  Len | length for this char in bytes

Definition at line 1562 of file dbus-string.c.

Referenced by _dbus_string_validate_utf8().

## ◆ UTF8_LENGTH

#define UTF8_LENGTH | ( |  | Char | ) |

Value:
((Char) < 0x80 ? 1 : \
((Char) < 0x800 ? 2 : \
((Char) < 0x10000 ? 3 : \
((Char) < 0x200000 ? 4 : \
((Char) < 0x4000000 ? 5 : 6)))))

computes length of a unicode character in UTF-8

Parameters

  Char | the char

Definition at line 1546 of file dbus-string.c.

Referenced by _dbus_string_validate_utf8().

## Function Documentation

## ◆ _dbus_parse_unix_group_from_config()

dbus_bool_t _dbus_parse_unix_group_from_config | ( | const DBusString * | groupname,
|  | dbus_gid_t * | gid_p
| ) |  |

Parse a UNIX group from the bus config file.

On Windows, this should simply always fail (just return FALSE).

Parameters

  groupname | the groupname text
  gid_p | place to return the gid

Returns
  TRUE on success

Definition at line 679 of file dbus-sysdeps-util-win.c.

References _dbus_get_group_id(), and FALSE.

## ◆ _dbus_parse_unix_user_from_config()

dbus_bool_t _dbus_parse_unix_user_from_config | ( | const DBusString * | username,
|  | dbus_uid_t * | uid_p
| ) |  |

Parse a UNIX user from the bus config file.

On Windows, this should simply always fail (just return FALSE).

Parameters

  username | the username text
  uid_p | place to return the uid

Returns
  TRUE on success

Definition at line 694 of file dbus-sysdeps-util-win.c.

References _dbus_get_user_id(), and FALSE.

## ◆ _dbus_string_align_length()

dbus_bool_t _dbus_string_align_length | ( | DBusString * | str,
|  | int | alignment
| ) |  |

Align the length of a string to a specific alignment (typically 4 or 8) by appending nul bytes to the string.

Parameters

  str | a string
  alignment | the alignment

Returns
  FALSE if no memory

Definition at line 883 of file dbus-string.c.

## ◆ _dbus_string_alloc_space()

dbus_bool_t _dbus_string_alloc_space | ( | DBusString * | str,
|  | int | extra_bytes
| ) |  |

Preallocate extra_bytes such that a future lengthening of the string by extra_bytes is guaranteed to succeed without an out of memory error.

Parameters

  str | a string
  extra_bytes | bytes to alloc

Returns
  FALSE if no memory

Definition at line 899 of file dbus-string.c.

References _dbus_string_lengthen(), _dbus_string_shorten(), FALSE, and TRUE.

Referenced by _dbus_type_writer_write_basic().

## ◆ _dbus_string_append()

dbus_bool_t _dbus_string_append | ( | DBusString * | str,
|  | const char * | buffer
| ) |  |

Appends a nul-terminated C-style string to a DBusString.

Parameters

  str | the DBusString
  buffer | the nul-terminated characters to append

Returns
  FALSE if not enough memory.

Definition at line 935 of file dbus-string.c.

References _dbus_assert, _DBUS_STRING_MAX_LENGTH, DBUS_STRING_PREAMBLE, FALSE, and NULL.

Referenced by _dbus_append_address_from_socket(), _dbus_append_keyring_directory_for_credentials(), _dbus_append_user_from_current_process(), _dbus_directory_get_next_file(), _dbus_directory_open(), _dbus_get_session_config_file(), _dbus_get_standard_session_servicedirs(), _dbus_get_system_config_file(), _dbus_hash_table_from_array(), _dbus_homedir_from_uid(), _dbus_homedir_from_username(), _dbus_is_console_user(), _dbus_listen_tcp_socket(), _dbus_server_listen_platform_specific(), _dbus_server_new_for_domain_socket(), _dbus_server_new_for_launchd(), _dbus_server_new_for_tcp_socket(), _dbus_set_up_transient_session_servicedirs(), _dbus_string_get_dirname(), _dbus_string_init_from_string(), _dbus_string_save_to_file(), _dbus_transport_new_for_tcp_socket(), and _dbus_user_at_console().

## ◆ _dbus_string_append_byte()

dbus_bool_t _dbus_string_append_byte | ( | DBusString * | str,
|  | unsigned char | byte
| ) |  |

Appends a single byte to the string, returning FALSE if not enough memory.

Parameters

  str | the string
  byte | the byte to append

Returns
  TRUE on success

Definition at line 1157 of file dbus-string.c.

References DBUS_STRING_PREAMBLE.

Referenced by _dbus_address_append_escaped(), _dbus_concat_dir_and_file(), _dbus_string_append_byte_as_hex(), _dbus_string_hex_decode(), and _dbus_write_uuid_file().

## ◆ _dbus_string_append_byte_as_hex()

dbus_bool_t _dbus_string_append_byte_as_hex | ( | DBusString * | str,
|  | unsigned char | byte
| ) |  |

Appends a two-character hex digit to a string, where the hex digit has the value of the given byte.

Parameters

  str | the string
  byte | the byte

Returns
  FALSE if no memory

Definition at line 2225 of file dbus-string.c.

References _dbus_string_append_byte(), _dbus_string_set_length(), FALSE, and TRUE.

Referenced by _dbus_address_append_escaped(), and _dbus_string_hex_encode().

## ◆ _dbus_string_append_int()

dbus_bool_t _dbus_string_append_int | ( | DBusString * | str,
|  | long | value
| ) |  |

Appends an integer to a DBusString.

Parameters

  str | the string
  value | the integer value

Returns
  FALSE if not enough memory or other failure.

Definition at line 356 of file dbus-sysdeps.c.

References _dbus_string_get_data_len(), _dbus_string_lengthen(), _dbus_string_shorten(), FALSE, and TRUE.

## ◆ _dbus_string_append_len()

dbus_bool_t _dbus_string_append_len | ( | DBusString * | str,
|  | const char * | buffer,
|  | int | len
| ) |  |

Appends block of bytes with the given length to a DBusString.

Parameters

  str | the DBusString
  buffer | the bytes to append
  len | the number of bytes to append

Returns
  FALSE if not enough memory.

Definition at line 1137 of file dbus-string.c.

References _dbus_assert, DBUS_STRING_PREAMBLE, and NULL.

Referenced by dbus_message_demarshal(), dbus_message_iter_get_signature(), and dbus_signature_iter_get_signature().

## ◆ _dbus_string_append_printf()

dbus_bool_t _dbus_string_append_printf | ( | DBusString * | str,
|  | const char * | format,
|  |  | ...
| ) |  |

Appends a printf-style formatted string to the DBusString.

Parameters

  str | the string
  format | printf format

Returns
  FALSE if no memory

Definition at line 1114 of file dbus-string.c.

References _dbus_string_append_printf_valist().

Referenced by _dbus_append_address_from_socket(), _dbus_command_for_pid(), _dbus_credentials_to_string_append(), _dbus_hash_table_to_array(), and _dbus_set_up_transient_session_servicedirs().

## ◆ _dbus_string_append_printf_valist()

dbus_bool_t _dbus_string_append_printf_valist | ( | DBusString * | str,
|  | const char * | format,
|  | va_list | args
| ) |  |

Appends a printf-style formatted string to the DBusString.

Parameters

  str | the string
  format | printf format
  args | variable argument list

Returns
  FALSE if no memory

Definition at line 1072 of file dbus-string.c.

References DBUS_STRING_PREAMBLE, and FALSE.

Referenced by _dbus_string_append_printf(), and dbus_message_new_error_printf().

## ◆ _dbus_string_append_uint()

dbus_bool_t _dbus_string_append_uint | ( | DBusString * | str,
|  | unsigned long | value
| ) |  |

Appends an unsigned integer to a DBusString.

Parameters

  str | the string
  value | the integer value

Returns
  FALSE if not enough memory or other failure.

Definition at line 394 of file dbus-sysdeps.c.

References _dbus_string_get_data_len(), _dbus_string_lengthen(), _dbus_string_shorten(), FALSE, and TRUE.

Referenced by _dbus_append_user_from_current_process().

## ◆ _dbus_string_chop_white()

void _dbus_string_chop_white | ( | DBusString * | str | ) |

Deletes leading and trailing whitespace.

Parameters

  str | the string

Definition at line 1989 of file dbus-string.c.

References _dbus_string_delete(), _dbus_string_set_length(), _dbus_string_skip_white(), and _dbus_string_skip_white_reverse().

Referenced by _dbus_split_paths_and_append().

## ◆ _dbus_string_compact()

dbus_bool_t _dbus_string_compact | ( | DBusString * | str,
|  | int | max_waste
| ) |  |

Compacts the string to avoid wasted memory.

Wasted memory is memory that is allocated but not actually required to store the current length of the string. The compact is only done if more than the given amount of memory is being wasted (otherwise the waste is ignored and the call does nothing).

Parameters

  str | the string
  max_waste | the maximum amount of waste to ignore

Returns
  FALSE if the compact failed due to realloc failure

Definition at line 389 of file dbus-string.c.

References DBUS_STRING_PREAMBLE.

## ◆ _dbus_string_copy()

dbus_bool_t _dbus_string_copy | ( | const DBusString * | source,
|  | int | start,
|  | DBusString * | dest,
|  | int | insert_at
| ) |  |

Like _dbus_string_move(), but does not delete the section of the source string that's copied to the dest string.

Parameters

  source | the source string
  start | where to start copying the source string
  dest | the destination string
  insert_at | where to place the copied part of source string

Returns
  FALSE if not enough memory

Definition at line 1283 of file dbus-string.c.

References DBUS_STRING_COPY_PREAMBLE.

Referenced by _dbus_append_keyring_directory_for_credentials(), _dbus_auth_server_new(), _dbus_command_for_pid(), _dbus_concat_dir_and_file(), _dbus_header_copy(), _dbus_string_save_to_file(), dbus_message_copy(), and dbus_message_marshal().

## ◆ _dbus_string_copy_data()

dbus_bool_t _dbus_string_copy_data | ( | const DBusString * | str,
|  | char ** | data_return
| ) |  |

Copies the data from the string into a char*.

Parameters

  str | the string
  data_return | place to return the data

Returns
  TRUE on success, FALSE on no memory

Definition at line 672 of file dbus-string.c.

References _dbus_assert, DBUS_CONST_STRING_PREAMBLE, dbus_malloc(), FALSE, DBusRealString::len, NULL, DBusRealString::str, and TRUE.

Referenced by _dbus_split_paths_and_append(), _dbus_transport_init_base(), and dbus_server_get_id().

## ◆ _dbus_string_copy_len()

dbus_bool_t _dbus_string_copy_len | ( | const DBusString * | source,
|  | int | start,
|  | int | len,
|  | DBusString * | dest,
|  | int | insert_at
| ) |  |

Like _dbus_string_copy(), but can copy a segment from the middle of the source string.

Parameters

  source | the source string
  start | where to start copying the source string
  len | length of segment to copy
  dest | the destination string
  insert_at | where to place the copied segment of source string

Returns
  FALSE if not enough memory

Definition at line 1375 of file dbus-string.c.

References _dbus_assert, and DBUS_STRING_COPY_PREAMBLE.

Referenced by _dbus_header_load(), _dbus_split_paths_and_append(), and _dbus_string_get_dirname().

## ◆ _dbus_string_copy_to_buffer()

void _dbus_string_copy_to_buffer | ( | const DBusString * | str,
|  | char * | buffer,
|  | int | avail_len
| ) |  |

Copies the contents of a DBusString into a different buffer.

It is a bug if avail_len is too short to hold the string contents. nul termination is not copied, just the supplied bytes.

Parameters

  str | a string
  buffer | a C buffer to copy data to
  avail_len | maximum length of C buffer

Definition at line 697 of file dbus-string.c.

References _dbus_assert, DBUS_CONST_STRING_PREAMBLE, DBusRealString::len, and DBusRealString::str.

Referenced by _dbus_generate_random_bytes_buffer().

## ◆ _dbus_string_copy_to_buffer_with_nul()

void _dbus_string_copy_to_buffer_with_nul | ( | const DBusString * | str,
|  | char * | buffer,
|  | int | avail_len
| ) |  |

Copies the contents of a DBusString into a different buffer.

It is a bug if avail_len is too short to hold the string contents plus a nul byte.

Parameters

  str | a string
  buffer | a C buffer to copy data to
  avail_len | maximum length of C buffer

Definition at line 719 of file dbus-string.c.

References _dbus_assert, DBUS_CONST_STRING_PREAMBLE, DBusRealString::len, and DBusRealString::str.

## ◆ _dbus_string_delete()

void _dbus_string_delete | ( | DBusString * | str,
|  | int | start,
|  | int | len
| ) |  |

Deletes a segment of a DBusString with length len starting at start.

(Hint: to clear an entire string, setting length to 0 with _dbus_string_set_length() is easier.)

Parameters

  str | the DBusString
  start | where to start deleting
  len | the number of bytes to delete

Definition at line 1193 of file dbus-string.c.

References _dbus_assert, and DBUS_STRING_PREAMBLE.

Referenced by _dbus_auth_bytes_sent(), and _dbus_string_chop_white().

## ◆ _dbus_string_ends_with_c_str()

dbus_bool_t _dbus_string_ends_with_c_str | ( | const DBusString * | a,
|  | const char * | c_str
| ) |  |

Returns whether a string ends with the given suffix.

Todo:
  memcmp might make this faster.

Parameters

  a | the string
  c_str | the C-style string

Returns
  TRUE if the string ends with the suffix

Definition at line 46 of file dbus-string-util.c.

References _dbus_assert, DBUS_GENERIC_STRING_PREAMBLE, FALSE, DBusRealString::len, NULL, DBusRealString::str, and TRUE.

Referenced by _dbus_directory_open().

## ◆ _dbus_string_equal()

dbus_bool_t _dbus_string_equal | ( | const DBusString * | a,
|  | const DBusString * | b
| ) |  |

Tests two DBusString for equality.

Todo:
  memcmp is probably faster

Parameters

  a | first string
  b | second string

Returns
  TRUE if equal

Definition at line 2013 of file dbus-string.c.

References DBUS_GENERIC_STRING_PREAMBLE, FALSE, DBusRealString::len, DBusRealString::str, and TRUE.

Referenced by dbus_error_has_name().

## ◆ _dbus_string_equal_c_str()

dbus_bool_t _dbus_string_equal_c_str | ( | const DBusString * | a,
|  | const char * | c_str
| ) |  |

Checks whether a string is equal to a C string.

Parameters

  a | the string
  c_str | the C string

Returns
  TRUE if equal

Definition at line 2152 of file dbus-string.c.

References _dbus_assert, DBUS_GENERIC_STRING_PREAMBLE, FALSE, DBusRealString::len, NULL, DBusRealString::str, and TRUE.

Referenced by dbus_address_entry_get_value().

## ◆ _dbus_string_equal_len()

dbus_bool_t _dbus_string_equal_len | ( | const DBusString * | a,
|  | const DBusString * | b,
|  | int | len
| ) |  |

Tests two DBusString for equality up to the given length.

The strings may be shorter than the given length.

Todo:
  write a unit test

Todo:
  memcmp is probably faster

Parameters

  a | first string
  b | second string
  len | the maximum length to look at

Returns
  TRUE if equal for the given number of bytes

Definition at line 2056 of file dbus-string.c.

References DBUS_GENERIC_STRING_PREAMBLE, FALSE, DBusRealString::len, DBusRealString::str, and TRUE.

## ◆ _dbus_string_equal_substring()

dbus_bool_t _dbus_string_equal_substring | ( | const DBusString * | a,
|  | int | a_start,
|  | int | a_len,
|  | const DBusString * | b,
|  | int | b_start
| ) |  |

Tests two sub-parts of two DBusString for equality.

The specified range of the first string must exist; the specified start position of the second string must exist.

Todo:
  write a unit test

Todo:
  memcmp is probably faster

Parameters

  a | first string
  a_start | where to start substring in first string
  a_len | length of substring in first string
  b | second string
  b_start | where to start substring in second string

Returns
  TRUE if the two substrings are equal

Definition at line 2104 of file dbus-string.c.

References _dbus_assert, DBUS_GENERIC_STRING_PREAMBLE, FALSE, DBusRealString::len, DBusRealString::str, and TRUE.

## ◆ _dbus_string_find()

dbus_bool_t _dbus_string_find | ( | const DBusString * | str,
|  | int | start,
|  | const char * | substr,
|  | int * | found
| ) |  |

Finds the given substring in the string, returning TRUE and filling in the byte index where the substring was found, if it was found.

Returns FALSE if the substring wasn't found. Sets *start to the length of the string if the substring is not found.

Parameters

  str | the string
  start | where to start looking
  substr | the substring
  found | return location for where it was found, or NULL

Returns
  TRUE if found

Definition at line 1604 of file dbus-string.c.

References _dbus_string_find_to().

Referenced by _dbus_keyring_validate_context(), _dbus_split_paths_and_append(), and _dbus_string_split_on_byte().

## ◆ _dbus_string_find_blank()

dbus_bool_t _dbus_string_find_blank | ( | const DBusString * | str,
|  | int | start,
|  | int * | found
| ) |  |

Finds a blank (space or tab) in the string.

Returns TRUE if found, FALSE otherwise. If a blank is not found sets *found to the length of the string.

Parameters

  str | the string
  start | byte index to start looking
  found | place to store the location of the first blank

Returns
  TRUE if a blank was found

Definition at line 1765 of file dbus-string.c.

References _dbus_assert, DBUS_CONST_STRING_PREAMBLE, FALSE, DBusRealString::len, DBusRealString::str, and TRUE.

Referenced by _dbus_keyring_validate_context().

## ◆ _dbus_string_find_byte_backward()

dbus_bool_t _dbus_string_find_byte_backward | ( | const DBusString * | str,
|  | int | start,
|  | unsigned char | byte,
|  | int * | found
| ) |  |

Find the given byte scanning backward from the given start.

Sets *found to -1 if the byte is not found.

Parameters

  str | the string
  start | the place to start scanning (will not find the byte at this point)
  byte | the byte to find
  found | return location for where it was found

Returns
  TRUE if found

Definition at line 90 of file dbus-string-util.c.

References _dbus_assert, DBUS_CONST_STRING_PREAMBLE, and NULL.

Referenced by _dbus_string_get_dirname().

## ◆ _dbus_string_find_eol()

dbus_bool_t _dbus_string_find_eol | ( | const DBusString * | str,
|  | int | start,
|  | int * | found,
|  | int * | found_len
| ) |  |

Finds end of line ("\r\n" or "\n") in the string, returning TRUE and filling in the byte index where the eol string was found, if it was found.

Returns FALSE if eol wasn't found.

Parameters

  str | the string
  start | where to start looking
  found | return location for where eol was found or string length otherwise
  found_len | return length of found eol string or zero otherwise

Returns
  TRUE if found

Definition at line 1627 of file dbus-string.c.

References _dbus_assert, DBUS_CONST_STRING_PREAMBLE, FALSE, DBusRealString::len, DBusRealString::str, and TRUE.

Referenced by _dbus_string_pop_line().

## ◆ _dbus_string_find_to()

dbus_bool_t _dbus_string_find_to | ( | const DBusString * | str,
|  | int | start,
|  | int | end,
|  | const char * | substr,
|  | int * | found
| ) |  |

Finds the given substring in the string, up to a certain position, returning TRUE and filling in the byte index where the substring was found, if it was found.

Returns FALSE if the substring wasn't found. Sets *start to the length of the string if the substring is not found.

Parameters

  str | the string
  start | where to start looking
  end | where to stop looking
  substr | the substring
  found | return location for where it was found, or NULL

Returns
  TRUE if found

Definition at line 1697 of file dbus-string.c.

References _dbus_assert, DBUS_CONST_STRING_PREAMBLE, FALSE, NULL, DBusRealString::str, and TRUE.

Referenced by _dbus_string_find().

## ◆ _dbus_string_free()

void _dbus_string_free | ( | DBusString * | str | ) |

Frees a string created by _dbus_string_init().

Parameters

  str | memory where the string is stored.

Definition at line 259 of file dbus-string.c.

References DBusRealString::align_offset, DBusRealString::constant, dbus_free(), DBUS_GENERIC_STRING_PREAMBLE, DBusRealString::invalid, NULL, DBusRealString::str, and TRUE.

Referenced by _dbus_append_keyring_directory_for_credentials(), _dbus_auth_server_new(), _dbus_command_for_pid(), _dbus_directory_open(), _dbus_generate_random_bytes_buffer(), _dbus_get_autolaunch_address(), _dbus_get_standard_session_servicedirs(), _dbus_hash_table_from_array(), _dbus_hash_table_to_array(), _dbus_header_copy(), _dbus_header_free(), _dbus_is_console_user(), _dbus_keyring_unref(), _dbus_message_loader_unref(), _dbus_read_credentials_socket(), _dbus_replace_install_prefix(), _dbus_server_finalize_base(), _dbus_server_listen_platform_specific(), _dbus_server_new_for_domain_socket(), _dbus_server_new_for_launchd(), _dbus_server_new_for_tcp_socket(), _dbus_set_up_transient_session_servicedirs(), _dbus_sha_compute(), _dbus_split_paths_and_append(), _dbus_string_hex_decode(), _dbus_string_hex_encode(), _dbus_string_save_to_file(), _dbus_user_at_console(), _dbus_write_uuid_file(), dbus_address_escape_value(), dbus_message_demarshal_bytes_needed(), dbus_message_iter_get_signature(), dbus_message_marshal(), dbus_message_new_error_printf(), dbus_signature_iter_get_signature(), and dbus_try_get_local_machine_id().

## ◆ _dbus_string_get_data_len()

char* _dbus_string_get_data_len | ( | DBusString * | str,
|  | int | start,
|  | int | len
| ) |  |

Gets a sub-portion of the raw character buffer from the string.

The "len" field is required simply for error checking, to be sure you don't try to use more string than exists. The nul termination of the returned buffer remains at the end of the entire string, not at start + len.

Parameters

  str | the string
  start | byte offset to return
  len | length of segment to return

Returns
  the string data

Definition at line 490 of file dbus-string.c.

References _dbus_assert, DBUS_STRING_PREAMBLE, and DBusRealString::str.

Referenced by _dbus_read(), _dbus_read_socket(), _dbus_read_socket_with_unix_fds(), _dbus_string_append_int(), and _dbus_string_append_uint().

## ◆ _dbus_string_get_dirname()

dbus_bool_t _dbus_string_get_dirname | ( | const DBusString * | filename,
|  | DBusString * | dirname
| ) |  |

Get the directory name from a complete filename.

Parameters

  filename | the filename
  dirname | string to append directory name to

Returns
  FALSE if no memory

Definition at line 1038 of file dbus-sysdeps-util-unix.c.

References _dbus_assert, _dbus_string_append(), _dbus_string_copy_len(), _dbus_string_find_byte_backward(), and NULL.

## ◆ _dbus_string_hex_decode()

dbus_bool_t _dbus_string_hex_decode | ( | const DBusString * | source,
|  | int | start,
|  | int * | end_return,
|  | DBusString * | dest,
|  | int | insert_at
| ) |  |

Decodes a string from hex encoding.

Parameters

  source | the string to decode
  start | byte index to start decode
  end_return | return location of the end of the hex data, or NULL
  dest | string where decoded data should be placed
  insert_at | where to place decoded data

Returns
  TRUE if decoding was successful, FALSE if no memory.

Definition at line 2309 of file dbus-string.c.

References _dbus_assert, _dbus_string_append_byte(), _dbus_string_free(), _dbus_string_init(), _dbus_string_move(), FALSE, and TRUE.

## ◆ _dbus_string_hex_encode()

dbus_bool_t _dbus_string_hex_encode | ( | const DBusString * | source,
|  | int | start,
|  | DBusString * | dest,
|  | int | insert_at
| ) |  |

Encodes a string in hex, the way MD5 and SHA-1 are usually encoded.

(Each byte is two hex digits.)

Parameters

  source | the string to encode
  start | byte index to start encoding
  dest | string where encoded data should be placed
  insert_at | where to place encoded data

Returns
  TRUE if encoding was successful, FALSE if no memory etc.

Definition at line 2259 of file dbus-string.c.

References _dbus_assert, _dbus_string_append_byte_as_hex(), _dbus_string_free(), _dbus_string_init(), _dbus_string_move(), FALSE, and TRUE.

Referenced by _dbus_sha_compute(), and _dbus_uuid_encode().

## ◆ _dbus_string_init()

dbus_bool_t _dbus_string_init | ( | DBusString * | str | ) |

Initializes a string.

The string starts life with zero length. The string must eventually be freed with _dbus_string_free().

Parameters

  str | memory to hold the string

Returns
  TRUE on success, FALSE if no memory

Definition at line 175 of file dbus-string.c.

References _dbus_string_init_preallocated().

Referenced by _dbus_append_keyring_directory_for_credentials(), _dbus_auth_client_new(), _dbus_auth_server_new(), _dbus_command_for_pid(), _dbus_generate_random_bytes_buffer(), _dbus_get_autolaunch_address(), _dbus_get_standard_session_servicedirs(), _dbus_hash_table_from_array(), _dbus_hash_table_to_array(), _dbus_is_console_user(), _dbus_keyring_new_for_credentials(), _dbus_read_credentials_socket(), _dbus_replace_install_prefix(), _dbus_server_init_base(), _dbus_server_listen_platform_specific(), _dbus_server_new_for_domain_socket(), _dbus_server_new_for_launchd(), _dbus_server_new_for_tcp_socket(), _dbus_set_up_transient_session_servicedirs(), _dbus_sha_compute(), _dbus_split_paths_and_append(), _dbus_string_hex_decode(), _dbus_string_hex_encode(), _dbus_string_init_from_string(), _dbus_string_save_to_file(), _dbus_transport_new_for_socket(), _dbus_transport_new_for_tcp_socket(), _dbus_user_at_console(), _dbus_write_uuid_file(), dbus_address_escape_value(), dbus_address_unescape_value(), dbus_message_iter_get_signature(), dbus_message_marshal(), dbus_message_new_error_printf(), dbus_signature_iter_get_signature(), and dbus_try_get_local_machine_id().

## ◆ _dbus_string_init_const()

void _dbus_string_init_const | ( | DBusString * | str,
|  | const char * | value
| ) |  |

Initializes a constant string.

The value parameter is not copied (should be static), and the string may never be modified. It is safe but not necessary to call _dbus_string_free() on a const string. The string has a length limit of MAXINT - 8.

Parameters

  str | memory to use for the string
  value | a string to be stored in str (not copied!!!)

Definition at line 190 of file dbus-string.c.

References _dbus_assert, _dbus_string_init_const_len(), and NULL.

Referenced by _dbus_append_address_from_socket(), _dbus_append_keyring_directory_for_credentials(), _dbus_change_to_daemon_user(), _dbus_get_standard_session_servicedirs(), _dbus_get_standard_system_servicedirs(), _dbus_read_local_machine_uuid(), _dbus_server_listen_platform_specific(), _dbus_server_new_for_domain_socket(), _dbus_server_new_for_tcp_socket(), _dbus_split_paths_and_append(), _dbus_user_at_console(), _dbus_verify_daemon_user(), dbus_address_escape_value(), dbus_address_unescape_value(), dbus_error_has_name(), dbus_internal_do_not_use_get_uuid(), dbus_parse_address(), dbus_signature_validate(), dbus_validate_bus_name(), dbus_validate_error_name(), dbus_validate_interface(), dbus_validate_member(), dbus_validate_path(), and dbus_validate_utf8().

## ◆ _dbus_string_init_const_len()

void _dbus_string_init_const_len | ( | DBusString * | str,
|  | const char * | value,
|  | int | len
| ) |  |

Initializes a constant string with a length.

The value parameter is not copied (should be static), and the string may never be modified. It is safe but not necessary to call _dbus_string_free() on a const string.

Parameters

  str | memory to use for the string
  value | a string to be stored in str (not copied!!!)
  len | the length to use

Definition at line 210 of file dbus-string.c.

References _dbus_assert, _DBUS_STRING_MAX_LENGTH, DBusRealString::align_offset, DBusRealString::allocated, DBusRealString::constant, FALSE, DBusRealString::invalid, DBusRealString::len, DBusRealString::locked, NULL, DBusRealString::str, and TRUE.

Referenced by _dbus_send_credentials_socket(), _dbus_string_init_const(), _dbus_uuid_encode(), and dbus_message_demarshal_bytes_needed().

## ◆ _dbus_string_init_from_string()

dbus_bool_t _dbus_string_init_from_string | ( | DBusString * | str,
|  | const DBusString * | from
| ) |  |

Initializes a string from another string.

The string must eventually be freed with _dbus_string_free().

Parameters

  str | memory to hold the string
  from | instance from which the string is initialized

Returns
  TRUE on success, FALSE if no memory

Definition at line 245 of file dbus-string.c.

References _dbus_string_append(), _dbus_string_init(), and FALSE.

Referenced by _dbus_directory_open().

## ◆ _dbus_string_init_preallocated()

dbus_bool_t _dbus_string_init_preallocated | ( | DBusString * | str,
|  | int | allocate_size
| ) |  |

Initializes a string that can be up to the given allocation size before it has to realloc.

The string starts life with zero length. The string must eventually be freed with _dbus_string_free().

Parameters

  str | memory to hold the string
  allocate_size | amount to preallocate

Returns
  TRUE on success, FALSE if no memory

Definition at line 132 of file dbus-string.c.

Referenced by _dbus_header_copy(), _dbus_header_init(), _dbus_string_init(), and dbus_message_copy().

## ◆ _dbus_string_insert_2_aligned()

dbus_bool_t _dbus_string_insert_2_aligned | ( | DBusString * | str,
|  | int | insert_at,
|  | const unsigned char | octets[2]
| ) |  |

Inserts 2 bytes aligned on a 2 byte boundary with any alignment padding initialized to 0.

Parameters

  str | the DBusString
  insert_at | where to insert
  octets | 2 bytes to insert

Returns
  FALSE if not enough memory.

Definition at line 972 of file dbus-string.c.

References DBUS_STRING_PREAMBLE.

## ◆ _dbus_string_insert_4_aligned()

dbus_bool_t _dbus_string_insert_4_aligned | ( | DBusString * | str,
|  | int | insert_at,
|  | const unsigned char | octets[4]
| ) |  |

Inserts 4 bytes aligned on a 4 byte boundary with any alignment padding initialized to 0.

Parameters

  str | the DBusString
  insert_at | where to insert
  octets | 4 bytes to insert

Returns
  FALSE if not enough memory.

Definition at line 996 of file dbus-string.c.

References DBUS_STRING_PREAMBLE.

## ◆ _dbus_string_insert_8_aligned()

dbus_bool_t _dbus_string_insert_8_aligned | ( | DBusString * | str,
|  | int | insert_at,
|  | const unsigned char | octets[8]
| ) |  |

Inserts 8 bytes aligned on an 8 byte boundary with any alignment padding initialized to 0.

Parameters

  str | the DBusString
  insert_at | where to insert
  octets | 8 bytes to insert

Returns
  FALSE if not enough memory.

Definition at line 1020 of file dbus-string.c.

References DBUS_STRING_PREAMBLE.

## ◆ _dbus_string_insert_alignment()

dbus_bool_t _dbus_string_insert_alignment | ( | DBusString * | str,
|  | int * | insert_at,
|  | int | alignment
| ) |  |

Inserts padding at *insert_at such to align it to the given boundary.

Initializes the padding to nul bytes. Sets *insert_at to the aligned position.

Parameters

  str | the DBusString
  insert_at | location to be aligned
  alignment | alignment boundary (1, 2, 4, or 8)

Returns
  FALSE if not enough memory.

Definition at line 1048 of file dbus-string.c.

References DBUS_STRING_PREAMBLE.

## ◆ _dbus_string_insert_byte()

dbus_bool_t _dbus_string_insert_byte | ( | DBusString * | str,
|  | int | i,
|  | unsigned char | byte
| ) |  |

Inserts a single byte at the given position.

Parameters

  str | the string
  i | the position
  byte | the value to insert

Returns
  TRUE on success

Definition at line 614 of file dbus-string.c.

References _dbus_assert, and DBUS_STRING_PREAMBLE.

Referenced by _dbus_marshal_write_basic().

## ◆ _dbus_string_insert_bytes()

dbus_bool_t _dbus_string_insert_bytes | ( | DBusString * | str,
|  | int | i,
|  | int | n_bytes,
|  | unsigned char | byte
| ) |  |

Inserts a number of bytes of a given value at the given position.

Parameters

  str | the string
  i | the position
  n_bytes | number of bytes
  byte | the value to insert

Returns
  TRUE on success

Definition at line 584 of file dbus-string.c.

References _dbus_assert, DBUS_STRING_PREAMBLE, and TRUE.

## ◆ _dbus_string_lengthen()

dbus_bool_t _dbus_string_lengthen | ( | DBusString * | str,
|  | int | additional_length
| ) |  |

Makes a string longer by the given number of bytes.

Checks whether adding additional_length to the current length would overflow an integer, and checks for exceeding a string's max length. The new bytes are not initialized, other than nul-terminating the end of the string. The uninitialized bytes may contain nul bytes or other junk.

Parameters

  str | a string
  additional_length | length to add to the string.

Returns
  TRUE on success.

Definition at line 760 of file dbus-string.c.

References _dbus_assert, _DBUS_STRING_MAX_LENGTH, DBUS_STRING_PREAMBLE, FALSE, and DBusRealString::len.

Referenced by _dbus_generate_random_bytes(), _dbus_read(), _dbus_read_socket(), _dbus_read_socket_with_unix_fds(), _dbus_string_alloc_space(), _dbus_string_append_int(), and _dbus_string_append_uint().

## ◆ _dbus_string_move()

dbus_bool_t _dbus_string_move | ( | DBusString * | source,
|  | int | start,
|  | DBusString * | dest,
|  | int | insert_at
| ) |  |

Moves the end of one string into another string.

Both strings must be initialized, valid strings.

Parameters

  source | the source string
  start | where to chop off the source string
  dest | the destination string
  insert_at | where to move the chopped-off part of source string

Returns
  FALSE if not enough memory

Definition at line 1259 of file dbus-string.c.

References _dbus_assert, _dbus_string_move_len(), and DBusRealString::len.

Referenced by _dbus_string_hex_decode(), and _dbus_string_hex_encode().

## ◆ _dbus_string_move_len()

dbus_bool_t _dbus_string_move_len | ( | DBusString * | source,
|  | int | start,
|  | int | len,
|  | DBusString * | dest,
|  | int | insert_at
| ) |  |

Like _dbus_string_move(), but can move a segment from the middle of the source string.

Parameters

  source | the source string
  start | first byte of source string to move
  len | length of segment to move
  dest | the destination string
  insert_at | where to move the bytes from the source string

Returns
  FALSE if not enough memory

Definition at line 1308 of file dbus-string.c.

References _dbus_assert, DBUS_STRING_COPY_PREAMBLE, and TRUE.

Referenced by _dbus_string_move(), _dbus_string_pop_line(), and _dbus_string_split_on_byte().

## ◆ _dbus_string_parse_int()

dbus_bool_t _dbus_string_parse_int | ( | const DBusString * | str,
|  | int | start,
|  | long * | value_return,
|  | int * | end_return
| ) |  |

Parses an integer contained in a DBusString.

Either return parameter may be NULL if you aren't interested in it. The integer is parsed and stored in value_return. Return parameters are not initialized if the function returns FALSE.

Parameters

  str | the string
  start | the byte index of the start of the integer
  value_return | return location of the integer value or NULL
  end_return | return location of the end of the integer, or NULL

Returns
  TRUE on success

Definition at line 437 of file dbus-sysdeps.c.

References _dbus_set_errno_to_zero(), FALSE, NULL, and TRUE.

Referenced by _dbus_parse_uid().

## ◆ _dbus_string_parse_uint()

dbus_bool_t _dbus_string_parse_uint | ( | const DBusString * | str,
|  | int | start,
|  | unsigned long * | value_return,
|  | int * | end_return
| ) |  |

Parses an unsigned integer contained in a DBusString.

Either return parameter may be NULL if you aren't interested in it. The integer is parsed and stored in value_return. Return parameters are not initialized if the function returns FALSE.

Parameters

  str | the string
  start | the byte index of the start of the integer
  value_return | return location of the integer value or NULL
  end_return | return location of the end of the integer, or NULL

Returns
  TRUE on success

Definition at line 476 of file dbus-sysdeps.c.

References _dbus_set_errno_to_zero(), FALSE, NULL, and TRUE.

Referenced by _dbus_is_a_number().

## ◆ _dbus_string_pop_line()

dbus_bool_t _dbus_string_pop_line | ( | DBusString * | source,
|  | DBusString * | dest
| ) |  |

Assigns a newline-terminated or \r\n-terminated line from the front of the string to the given dest string.

The dest string's previous contents are deleted. If the source string contains no newline, moves the entire source string to the dest string.

Todo:
  owen correctly notes that this is a stupid function (it was written purely for test code, e.g. dbus-message-builder.c). Probably should be enforced as test code only with ifdef DBUS_ENABLE_EMBEDDED_TESTS

Parameters

  source | the source string
  dest | the destination string (contents are replaced)

Returns
  FALSE if no memory, or source has length 0

Definition at line 1909 of file dbus-string.c.

References _dbus_assert, _dbus_assert_not_reached, _dbus_string_find_eol(), _dbus_string_move_len(), _dbus_string_set_length(), FALSE, and TRUE.

## ◆ _dbus_string_replace_len()

dbus_bool_t _dbus_string_replace_len | ( | const DBusString * | source,
|  | int | start,
|  | int | len,
|  | DBusString * | dest,
|  | int | replace_at,
|  | int | replace_len
| ) |  |

Replaces a segment of dest string with a segment of source string.

Parameters

  source | the source string
  start | where to start copying the source string
  len | length of segment to copy
  dest | the destination string
  replace_at | start of segment of dest string to replace
  replace_len | length of segment of dest string to replace

Returns
  FALSE if not enough memory

Definition at line 1404 of file dbus-string.c.

References _dbus_assert, and DBUS_STRING_COPY_PREAMBLE.

Referenced by _dbus_auth_set_context(), and _dbus_replace_install_prefix().

## ◆ _dbus_string_set_length()

dbus_bool_t _dbus_string_set_length | ( | DBusString * | str,
|  | int | length
| ) |  |

Sets the length of a string.

Can be used to truncate or lengthen the string. If the string is lengthened, the function may fail and return FALSE. Newly-added bytes are not initialized, as with _dbus_string_lengthen().

Parameters

  str | a string
  length | new length of the string.

Returns
  FALSE on failure.

Definition at line 802 of file dbus-string.c.

References _dbus_assert, and DBUS_STRING_PREAMBLE.

Referenced by _dbus_address_append_escaped(), _dbus_append_keyring_directory_for_credentials(), _dbus_auth_delete_unused_bytes(), _dbus_directory_get_next_file(), _dbus_file_get_contents(), _dbus_generate_random_bytes(), _dbus_hash_table_from_array(), _dbus_header_reinit(), _dbus_read(), _dbus_read_socket(), _dbus_read_socket_with_unix_fds(), _dbus_string_append_byte_as_hex(), _dbus_string_chop_white(), _dbus_string_pop_line(), and _dbus_string_split_on_byte().

## ◆ _dbus_string_shorten()

void _dbus_string_shorten | ( | DBusString * | str,
|  | int | length_to_remove
| ) |  |

Makes a string shorter by the given number of bytes.

Parameters

  str | a string
  length_to_remove | length to remove from the string.

Definition at line 780 of file dbus-string.c.

References _dbus_assert, and DBUS_STRING_PREAMBLE.

Referenced by _dbus_concat_dir_and_file(), _dbus_lookup_launchd_socket(), _dbus_string_alloc_space(), _dbus_string_append_int(), and _dbus_string_append_uint().

## ◆ _dbus_string_skip_blank()

void _dbus_string_skip_blank | ( | const DBusString * | str,
|  | int | start,
|  | int * | end
| ) |  |

Skips blanks from start, storing the first non-blank in *end (blank is space or tab).

Parameters

  str | the string
  start | where to start
  end | where to store the first non-blank byte index

Definition at line 1803 of file dbus-string.c.

References _dbus_assert, DBUS_CONST_STRING_PREAMBLE, DBUS_IS_ASCII_BLANK, DBUS_IS_ASCII_WHITE, DBusRealString::len, and DBusRealString::str.

## ◆ _dbus_string_skip_white()

void _dbus_string_skip_white | ( | const DBusString * | str,
|  | int | start,
|  | int * | end
| ) |  |

Skips whitespace from start, storing the first non-whitespace in *end.

(whitespace is space, tab, newline, CR).

Parameters

  str | the string
  start | where to start
  end | where to store the first non-whitespace byte index

Definition at line 1837 of file dbus-string.c.

References _dbus_assert, DBUS_CONST_STRING_PREAMBLE, DBUS_IS_ASCII_WHITE, DBusRealString::len, and DBusRealString::str.

Referenced by _dbus_string_chop_white().

## ◆ _dbus_string_skip_white_reverse()

void _dbus_string_skip_white_reverse | ( | const DBusString * | str,
|  | int | end,
|  | int * | start
| ) |  |

Skips whitespace from end, storing the start index of the trailing whitespace in *start.

(whitespace is space, tab, newline, CR).

Parameters

  str | the string
  end | where to start scanning backward
  start | where to store the start of whitespace chars

Definition at line 1870 of file dbus-string.c.

References _dbus_assert, DBUS_CONST_STRING_PREAMBLE, DBUS_IS_ASCII_WHITE, and DBusRealString::str.

Referenced by _dbus_string_chop_white().

## ◆ _dbus_string_split_on_byte()

dbus_bool_t _dbus_string_split_on_byte | ( | DBusString * | source,
|  | unsigned char | byte,
|  | DBusString * | tail
| ) |  |

Looks for the first occurance of a byte, deletes that byte, and moves everything after the byte to the beginning of a separate string.

Both strings must be initialized, valid strings.

Parameters

  source | the source string
  byte | the byte to remove and split the string at
  tail | the split off string

Returns
  FALSE if not enough memory or if byte could not be found

Definition at line 1467 of file dbus-string.c.

References _dbus_string_find(), _dbus_string_move_len(), _dbus_string_set_length(), FALSE, and TRUE.

Referenced by _dbus_hash_table_from_array().

## ◆ _dbus_string_starts_with_c_str()

dbus_bool_t _dbus_string_starts_with_c_str | ( | const DBusString * | a,
|  | const char * | c_str
| ) |  |

Checks whether a string starts with the given C string.

Parameters

  a | the string
  c_str | the C string

Returns
  TRUE if string starts with it

Definition at line 2188 of file dbus-string.c.

References _dbus_assert, DBUS_GENERIC_STRING_PREAMBLE, FALSE, DBusRealString::len, NULL, DBusRealString::str, and TRUE.

Referenced by _dbus_replace_install_prefix().

## ◆ _dbus_string_steal_data()

dbus_bool_t _dbus_string_steal_data | ( | DBusString * | str,
|  | char ** | data_return
| ) |  |

Like _dbus_string_get_data(), but removes the gotten data from the original string.

The caller must free the data returned. This function may fail due to lack of memory, and return FALSE.

Parameters

  str | the string
  data_return | location to return the buffer

Returns
  TRUE on success

Definition at line 641 of file dbus-string.c.

References _dbus_assert, DBUS_STRING_PREAMBLE, and NULL.

Referenced by _dbus_hash_table_from_array(), _dbus_hash_table_to_array(), _dbus_set_up_transient_session_servicedirs(), dbus_address_escape_value(), dbus_message_iter_get_signature(), dbus_message_marshal(), dbus_signature_iter_get_signature(), and dbus_try_get_local_machine_id().

## ◆ _dbus_string_tolower_ascii()

void _dbus_string_tolower_ascii | ( | const DBusString * | str,
|  | int | start,
|  | int | len
| ) |  |

Converts the given range of the string to lower case.

Parameters

  str | the string
  start | first byte index to convert
  len | number of bytes to convert

Definition at line 2485 of file dbus-string.c.

References _dbus_assert, DBUS_STRING_PREAMBLE, and DBusRealString::str.

## ◆ _dbus_string_toupper_ascii()

void _dbus_string_toupper_ascii | ( | const DBusString * | str,
|  | int | start,
|  | int | len
| ) |  |

Converts the given range of the string to upper case.

Parameters

  str | the string
  start | first byte index to convert
  len | number of bytes to convert

Definition at line 2516 of file dbus-string.c.

References _dbus_assert, DBUS_STRING_PREAMBLE, and DBusRealString::str.

## ◆ _dbus_string_validate_ascii()

dbus_bool_t _dbus_string_validate_ascii | ( | const DBusString * | str,
|  | int | start,
|  | int | len
| ) |  |

Checks that the given range of the string is valid ASCII with no nul bytes.

If the given range is not entirely contained in the string, returns FALSE.

Todo:
  this is inconsistent with most of DBusString in that it allows a start,len range that extends past the string end.

Parameters

  str | the string
  start | first byte index to check
  len | number of bytes to check

Returns
  TRUE if the byte range exists and is all valid ASCII

Definition at line 2450 of file dbus-string.c.

References _dbus_assert, DBUS_CONST_STRING_PREAMBLE, FALSE, DBusRealString::len, DBusRealString::str, and TRUE.

Referenced by _dbus_generate_random_ascii(), and _dbus_keyring_validate_context().

## ◆ _dbus_string_validate_nul()

dbus_bool_t _dbus_string_validate_nul | ( | const DBusString * | str,
|  | int | start,
|  | int | len
| ) |  |

Checks that the given range of the string is all nul bytes.

If the given range is not entirely contained in the string, returns FALSE.

Todo:
  this is inconsistent with most of DBusString in that it allows a start,len range that extends past the string end.

Parameters

  str | the string
  start | first byte index to check
  len | number of bytes to check

Returns
  TRUE if the byte range exists and is all nul bytes

Definition at line 2653 of file dbus-string.c.

References _dbus_assert, DBUS_CONST_STRING_PREAMBLE, FALSE, DBusRealString::len, DBusRealString::str, and TRUE.

## ◆ _dbus_string_validate_utf8()

dbus_bool_t _dbus_string_validate_utf8 | ( | const DBusString * | str,
|  | int | start,
|  | int | len
| ) |  |

Checks that the given range of the string is valid UTF-8.

If the given range is not entirely contained in the string, returns FALSE. If the string contains any nul bytes in the given range, returns FALSE. If the start and start+len are not on character boundaries, returns FALSE.

Todo:
  this is inconsistent with most of DBusString in that it allows a start,len range that extends past the string end.

Parameters

  str | the string
  start | first byte index to check
  len | number of bytes to check

Returns
  TRUE if the byte range exists and is all valid UTF-8

Definition at line 2555 of file dbus-string.c.

References _dbus_assert, DBUS_CONST_STRING_PREAMBLE, FALSE, DBusRealString::len, DBusRealString::str, TRUE, UNICODE_VALID, UTF8_COMPUTE, UTF8_GET, and UTF8_LENGTH.

Referenced by dbus_validate_bus_name(), dbus_validate_error_name(), dbus_validate_interface(), dbus_validate_member(), dbus_validate_path(), and dbus_validate_utf8().

## ◆ _dbus_string_zero()

void _dbus_string_zero | ( | DBusString * | str | ) |

Clears all allocated bytes in the string to zero.

Parameters

  str | the string

Definition at line 2685 of file dbus-string.c.

References DBusRealString::align_offset, DBusRealString::allocated, DBUS_STRING_PREAMBLE, and DBusRealString::str.

## ◆ _dbus_unix_groups_from_uid()

dbus_bool_t _dbus_unix_groups_from_uid | ( | dbus_uid_t | uid,
|  | dbus_gid_t ** | group_ids,
|  | int * | n_group_ids
| ) |  |

Gets all groups corresponding to the given UNIX user ID.

On UNIX, just calls _dbus_groups_from_uid(). On Windows, should always fail since we don't know any UNIX groups.

Parameters

  uid | the UID
  group_ids | return location for array of group IDs
  n_group_ids | return location for length of returned array

Returns
  TRUE if the UID existed and we got some credentials

Definition at line 712 of file dbus-sysdeps-util-win.c.

References _dbus_groups_from_uid(), and FALSE.

## ◆ _dbus_unix_user_is_at_console()

dbus_bool_t _dbus_unix_user_is_at_console | ( | dbus_uid_t | uid,
|  | DBusError * | error
| ) |  |

Checks to see if the UNIX user ID is at the console.

Should always fail on Windows (set the error to DBUS_ERROR_NOT_SUPPORTED).

Parameters

  uid | UID of person to check
  error | return location for errors

Returns
  TRUE if the UID is the same as the console user and there are no errors

Definition at line 661 of file dbus-sysdeps-util-win.c.

References _dbus_is_console_user(), DBUS_ERROR_NOT_SUPPORTED, dbus_set_error(), and FALSE.

## ◆ _dbus_unix_user_is_process_owner()

dbus_bool_t _dbus_unix_user_is_process_owner | ( | dbus_uid_t | uid | ) |

Checks to see if the UNIX user ID matches the UID of the process.

Should always return FALSE on Windows.

Parameters

  uid | the UNIX user ID

Returns
  TRUE if this uid owns the process.

Definition at line 637 of file dbus-sysdeps-util-win.c.

References _dbus_geteuid(), and FALSE.

## ◆ _dbus_windows_user_is_process_owner()

dbus_bool_t _dbus_windows_user_is_process_owner | ( | const char * | windows_sid | ) |

Checks to see if the Windows user SID matches the owner of the process.

Should always return FALSE on UNIX.

Parameters

  windows_sid | the Windows user SID

Returns
  TRUE if this user owns the process.

Definition at line 642 of file dbus-sysdeps-util-win.c.

References FALSE, and TRUE.