Update some paths in HACKING
[platform/upstream/dbus.git] / dbus / dbus-marshal.c
index 9856930..00821da 100644 (file)
@@ -2,9 +2,9 @@
 /* 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
+ * Licensed under the Academic Free License version 2.1
  * 
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -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
@@ -1478,7 +1518,7 @@ _dbus_demarshal_basic_type_array (const DBusString      *str,
     case DBUS_TYPE_INT32:
     case DBUS_TYPE_UINT32:
       return demarshal_4_octets_array (str, byte_order, *pos, pos,
-                                      (dbus_uint32_t *array, array_len);
+                                      (dbus_uint32_t **)array, array_len);
       break;
 #ifdef DBUS_HAVE_INT64
     case DBUS_TYPE_INT64:
@@ -1584,32 +1624,24 @@ _dbus_demarshal_string_array (const DBusString   *str,
 #define VERBOSE_DECOMPOSE 0
 
 /**
- * Demarshals an object path.  A path of just "/" is
+ * Decompose an object path.  A path of just "/" is
  * represented as an empty vector of strings.
  * 
- * @param str the string containing the data
- * @param byte_order the byte order
- * @param pos the position in the string
- * @param new_pos the new position of the string
+ * @param data the path data
+ * @param len  the length of the path string
  * @param path address to store new object path
  * @param path_len length of stored path
  */
 dbus_bool_t
-_dbus_demarshal_object_path (const DBusString *str,
-                             int               byte_order,
-                             int               pos,
-                             int              *new_pos,
-                             char           ***path,
-                             int              *path_len)
+_dbus_decompose_path (const char*     data,
+                      int             len,
+                      char         ***path,
+                      int            *path_len)
 {
-  int len;
   char **retval;
-  const char *data;
   int n_components;
   int i, j, comp;
-  
-  len = _dbus_demarshal_uint32 (str, byte_order, pos, &pos);
-  data = _dbus_string_get_const_data_len (str, pos, len + 1);
+
   _dbus_assert (data != NULL);
 
 #if VERBOSE_DECOMPOSE
@@ -1673,9 +1705,40 @@ _dbus_demarshal_object_path (const DBusString *str,
   if (path_len)
     *path_len = n_components;
   
+  return TRUE;
+}
+
+/**
+ * Demarshals an object path.  A path of just "/" is
+ * represented as an empty vector of strings.
+ * 
+ * @param str the string containing the data
+ * @param byte_order the byte order
+ * @param pos the position in the string
+ * @param new_pos the new position of the string
+ * @param path address to store new object path
+ * @param path_len length of stored path
+ */
+dbus_bool_t
+_dbus_demarshal_object_path (const DBusString *str,
+                             int               byte_order,
+                             int               pos,
+                             int              *new_pos,
+                             char           ***path,
+                             int              *path_len)
+{
+  int len;
+  const char *data;
+  
+  len = _dbus_demarshal_uint32 (str, byte_order, pos, &pos);
+  data = _dbus_string_get_const_data_len (str, pos, len + 1);
+
+  if (!_dbus_decompose_path (data, len, path, path_len))
+    return FALSE;
+
   if (new_pos)
     *new_pos = pos + len + 1;
-  
+
   return TRUE;
 }
 
@@ -2562,7 +2625,9 @@ _dbus_marshal_test (void)
   int pos = 0, len;
   dbus_int32_t array1[3] = { 0x123, 0x456, 0x789 }, *array2;
 #ifdef DBUS_HAVE_INT64
-  dbus_int64_t array3[3] = { 0x123ffffffff, 0x456ffffffff, 0x789ffffffff }, *array4;
+  dbus_int64_t array3[3] = { DBUS_INT64_CONSTANT (0x123ffffffff), 
+                             DBUS_INT64_CONSTANT (0x456ffffffff), 
+                             DBUS_INT64_CONSTANT (0x789ffffffff) }, *array4;
 #endif
   char *s;
   DBusString t;
@@ -2607,12 +2672,12 @@ _dbus_marshal_test (void)
   /* Marshal signed integers */
   if (!_dbus_marshal_int64 (&str, DBUS_BIG_ENDIAN, DBUS_INT64_CONSTANT (-0x123456789abc7)))
     _dbus_assert_not_reached ("could not marshal signed integer value");
-  if (!_dbus_demarshal_int64 (&str, DBUS_BIG_ENDIAN, pos, &pos) == DBUS_INT64_CONSTANT (-0x123456789abc7))
+  if (_dbus_demarshal_int64 (&str, DBUS_BIG_ENDIAN, pos, &pos) != DBUS_INT64_CONSTANT (-0x123456789abc7))
     _dbus_assert_not_reached ("demarshal failed");
 
   if (!_dbus_marshal_int64 (&str, DBUS_LITTLE_ENDIAN, DBUS_INT64_CONSTANT (-0x123456789abc7)))
     _dbus_assert_not_reached ("could not marshal signed integer value");
-  if (!_dbus_demarshal_int64 (&str, DBUS_LITTLE_ENDIAN, pos, &pos) == DBUS_INT64_CONSTANT (-0x123456789abc7))
+  if (_dbus_demarshal_int64 (&str, DBUS_LITTLE_ENDIAN, pos, &pos) != DBUS_INT64_CONSTANT (-0x123456789abc7))
     _dbus_assert_not_reached ("demarshal failed");
   
   /* Marshal unsigned integers */