summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-marshal.c
diff options
context:
space:
mode:
Diffstat (limited to 'dbus/dbus-marshal.c')
-rw-r--r--dbus/dbus-marshal.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/dbus/dbus-marshal.c b/dbus/dbus-marshal.c
index 01bb6a17..267fa0f6 100644
--- a/dbus/dbus-marshal.c
+++ b/dbus/dbus-marshal.c
@@ -2,7 +2,7 @@
/* dbus-marshal.c Marshalling routines
*
* Copyright (C) 2002 CodeFactory AB
- * Copyright (C) 2003 Red Hat, Inc.
+ * Copyright (C) 2003, 2004 Red Hat, Inc.
*
* Licensed under the Academic Free License version 2.0
*
@@ -608,6 +608,46 @@ _dbus_marshal_string (DBusString *str,
}
/**
+ * Marshals a UTF-8 string
+ *
+ * @todo: If the string append fails we need to restore
+ * the old length. (also for other marshallers)
+ *
+ * @param str the string to append the marshalled value to
+ * @param byte_order the byte order to use
+ * @param value the string
+ * @param len length of string to marshal in bytes
+ * @returns #TRUE on success
+ */
+dbus_bool_t
+_dbus_marshal_string_len (DBusString *str,
+ int byte_order,
+ const char *value,
+ int len)
+{
+ int old_string_len;
+
+ old_string_len = _dbus_string_get_length (str);
+
+ if (!_dbus_marshal_uint32 (str, byte_order, len))
+ {
+ /* Restore the previous length */
+ _dbus_string_set_length (str, old_string_len);
+
+ return FALSE;
+ }
+
+ if (!_dbus_string_append_len (str, value, len))
+ return FALSE;
+
+ /* add a nul byte */
+ if (!_dbus_string_lengthen (str, 1))
+ return FALSE;
+
+ return TRUE;
+}
+
+/**
* Marshals a byte array
*
* @param str the string to append the marshalled value to