EXPORT_C #endif void _dbus_marshal_byteswap (const DBusString *signature, int signature_start, int old_byte_order, int new_byte_order, DBusString *value_str, int value_pos) { DBusTypeReader reader; _dbus_assert (value_pos >= 0); _dbus_assert (value_pos <= _dbus_string_get_length (value_str)); if (old_byte_order == new_byte_order) return; _dbus_type_reader_init_types_only (&reader, signature, signature_start); #ifndef __SYMBIAN32__ byteswap_body_helper (&reader, TRUE, old_byte_order, new_byte_order, _dbus_string_get_data_len (value_str, value_pos, 0), NULL); #else byteswap_body_helper (&reader, TRUE, old_byte_order, new_byte_order, (unsigned char *)_dbus_string_get_data_len (value_str, value_pos, 0), NULL); #endif }
/** * Appends an unsigned integer to a DBusString. * * @param str the string * @param value the integer value * @returns #FALSE if not enough memory or other failure. */ dbus_bool_t _dbus_string_append_uint (DBusString *str, unsigned long value) { /* this is wrong, but definitely on the high side. */ #define MAX_ULONG_LEN (MAX_LONG_LEN * 2) int orig_len; int i; char *buf; orig_len = _dbus_string_get_length (str); if (!_dbus_string_lengthen (str, MAX_ULONG_LEN)) return FALSE; buf = _dbus_string_get_data_len (str, orig_len, MAX_ULONG_LEN); snprintf (buf, MAX_ULONG_LEN, "%lu", value); i = 0; while (*buf) { ++buf; ++i; } _dbus_string_shorten (str, MAX_ULONG_LEN - i); return TRUE; }
/** * Appends an integer to a DBusString. * * @param str the string * @param value the integer value * @returns #FALSE if not enough memory or other failure. */ dbus_bool_t _dbus_string_append_int (DBusString *str, long value) { /* this calculation is from comp.lang.c faq */ #define MAX_LONG_LEN ((sizeof (long) * 8 + 2) / 3 + 1) /* +1 for '-' */ int orig_len; int i; char *buf; orig_len = _dbus_string_get_length (str); if (!_dbus_string_lengthen (str, MAX_LONG_LEN)) return FALSE; buf = _dbus_string_get_data_len (str, orig_len, MAX_LONG_LEN); snprintf (buf, MAX_LONG_LEN, "%ld", value); i = 0; while (*buf) { ++buf; ++i; } _dbus_string_shorten (str, MAX_LONG_LEN - i); return TRUE; }
/** * Appends a double to a DBusString. * * @param str the string * @param value the floating point value * @returns #FALSE if not enough memory or other failure. */ dbus_bool_t _dbus_string_append_double (DBusString *str, double value) { #define MAX_DOUBLE_LEN 64 /* this is completely made up :-/ */ int orig_len; char *buf; int i; orig_len = _dbus_string_get_length (str); if (!_dbus_string_lengthen (str, MAX_DOUBLE_LEN)) return FALSE; buf = _dbus_string_get_data_len (str, orig_len, MAX_DOUBLE_LEN); snprintf (buf, MAX_LONG_LEN, "%g", value); i = 0; while (*buf) { ++buf; ++i; } _dbus_string_shorten (str, MAX_DOUBLE_LEN - i); return TRUE; }
/** * Toggles a message flag bit, turning on the bit if value = TRUE and * flipping it off if value = FALSE. * * @param header the header * @param flag the message flag to toggle * @param value toggle on or off */ void _dbus_header_toggle_flag (DBusHeader *header, dbus_uint32_t flag, dbus_bool_t value) { unsigned char *flags_p; flags_p = _dbus_string_get_data_len (&header->data, FLAGS_OFFSET, 1); if (value) *flags_p |= flag; else *flags_p &= ~flag; }
/** * Thin wrapper around the read() system call that appends * the data it reads to the DBusString buffer. It appends * up to the given count. * * @param hnd the HANDLE to read from * @param buffer the buffer to append data to * @param count the amount of data to read * @param error place to set an error * @returns the number of bytes read or -1 */ static int _dbus_file_read (HANDLE hnd, DBusString *buffer, int count, DBusError *error) { BOOL result; DWORD bytes_read; int start; char *data; _DBUS_ASSERT_ERROR_IS_CLEAR (error); _dbus_assert (count >= 0); start = _dbus_string_get_length (buffer); if (!_dbus_string_lengthen (buffer, count)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); return -1; } data = _dbus_string_get_data_len (buffer, start, count); result = ReadFile (hnd, data, count, &bytes_read, NULL); if (result == 0) { char *emsg = _dbus_win_error_string (GetLastError ()); dbus_set_error (error, _dbus_win_error_from_last_error (), "Failed to read from 0x%x: %s", hnd, emsg); _dbus_win_free_error_string (emsg); return -1; } if (bytes_read) { /* put length back (doesn't actually realloc) */ _dbus_string_set_length (buffer, start + bytes_read); #if 0 if (bytes_read > 0) _dbus_verbose_bytes_of_string (buffer, start, bytes_read); #endif } return bytes_read; }