summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2009-06-25 11:30:23 +0200
committerAlexander Larsson <alexl@redhat.com>2009-06-25 21:00:37 +0200
commit48842732168909ce3b4c9136a28c2e5a5a25d98b (patch)
treea5ef8e0fc9ca7220a62b942683ef0e673b7ba3ad
parentb305422b727c3ca5d30f4c9f97cf8fd779410398 (diff)
downloadgvfs-48842732168909ce3b4c9136a28c2e5a5a25d98b.tar.gz
Support (de)marshalling of new GFileInfo keys (invalid & stringv)
-rw-r--r--common/gvfsdaemonprotocol.c63
-rw-r--r--common/gvfsfileinfo.c45
2 files changed, 99 insertions, 9 deletions
diff --git a/common/gvfsdaemonprotocol.c b/common/gvfsdaemonprotocol.c
index c90a7ba2..7097d15b 100644
--- a/common/gvfsdaemonprotocol.c
+++ b/common/gvfsdaemonprotocol.c
@@ -47,6 +47,14 @@ get_object_signature (GObject *obj)
}
static void
+append_strv (DBusMessageIter *iter, char **strv)
+{
+ _g_dbus_message_iter_append_args (iter,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &strv, g_strv_length (strv),
+ 0);
+}
+
+static void
append_object (DBusMessageIter *iter, GObject *obj)
{
DBusMessageIter obj_struct_iter;
@@ -100,6 +108,9 @@ _g_dbus_attribute_value_destroy (GFileAttributeType type,
case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING:
g_free (value->ptr);
break;
+ case G_FILE_ATTRIBUTE_TYPE_STRINGV:
+ g_strfreev (value->ptr);
+ break;
case G_FILE_ATTRIBUTE_TYPE_OBJECT:
if (value->ptr)
g_object_unref (value->ptr);
@@ -136,6 +147,9 @@ _g_dbus_type_from_file_attribute_type (GFileAttributeType type)
case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING:
dbus_type = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_BYTE_AS_STRING;
break;
+ case G_FILE_ATTRIBUTE_TYPE_STRINGV:
+ dbus_type = DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING;
+ break;
case G_FILE_ATTRIBUTE_TYPE_BOOLEAN:
dbus_type = DBUS_TYPE_BOOLEAN_AS_STRING;
break;
@@ -154,6 +168,9 @@ _g_dbus_type_from_file_attribute_type (GFileAttributeType type)
case G_FILE_ATTRIBUTE_TYPE_OBJECT:
dbus_type = DBUS_TYPE_STRUCT_AS_STRING;
break;
+ case G_FILE_ATTRIBUTE_TYPE_INVALID:
+ dbus_type = DBUS_TYPE_BYTE_AS_STRING;
+ break;
default:
dbus_type = NULL;
g_warning ("Invalid attribute type %u, ignoring\n", type);
@@ -201,8 +218,17 @@ _g_dbus_append_file_attribute (DBusMessageIter *iter,
DBUS_TYPE_STRING, &value_p))
_g_dbus_oom ();
}
- else if (dbus_type[0] == DBUS_TYPE_ARRAY)
+ else if (dbus_type[0] == DBUS_TYPE_ARRAY && dbus_type[1] == DBUS_TYPE_BYTE)
_g_dbus_message_iter_append_cstring (&variant_iter, (char *)value_p);
+ else if (dbus_type[0] == DBUS_TYPE_ARRAY && dbus_type[1] == DBUS_TYPE_STRING)
+ append_strv (&variant_iter, (char **)value_p);
+ else if (dbus_type[0] == DBUS_TYPE_BYTE)
+ {
+ char byte = 0;
+ if (!dbus_message_iter_append_basic (&variant_iter,
+ DBUS_TYPE_BYTE, &byte))
+ _g_dbus_oom ();
+ }
else if (dbus_type[0] == DBUS_STRUCT_BEGIN_CHAR)
append_object (&variant_iter, (GObject *)value_p);
else if (dbus_type[0] == DBUS_TYPE_BOOLEAN)
@@ -286,8 +312,10 @@ _g_dbus_get_file_attribute (DBusMessageIter *iter,
int n_elements;
DBusMessageIter inner_struct_iter, variant_iter, cstring_iter, obj_iter;
const gchar *attribute_temp;
+ int element_type;
dbus_uint32_t obj_type;
dbus_bool_t dbus_bool;
+ guint8 byte;
GObject *obj;
dbus_message_iter_recurse (iter, &inner_struct_iter);
@@ -313,15 +341,34 @@ _g_dbus_get_file_attribute (DBusMessageIter *iter,
value->ptr = g_strdup (str);
break;
case DBUS_TYPE_ARRAY:
- if (dbus_message_iter_get_element_type (&variant_iter) != DBUS_TYPE_BYTE)
- goto error;
+ element_type = dbus_message_iter_get_element_type (&variant_iter);
+ if (element_type == DBUS_TYPE_BYTE)
+ {
+ *type = G_FILE_ATTRIBUTE_TYPE_BYTE_STRING;
- *type = G_FILE_ATTRIBUTE_TYPE_BYTE_STRING;
+ dbus_message_iter_recurse (&variant_iter, &cstring_iter);
+ dbus_message_iter_get_fixed_array (&cstring_iter,
+ &str, &n_elements);
+ value->ptr = g_strndup (str, n_elements);
+ }
+ else if (element_type == DBUS_TYPE_STRING)
+ {
+ char **strv;
+ int n_elements;
+ if (!_g_dbus_message_iter_get_args (iter, NULL,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &strv, &n_elements,
+ 0))
+ goto error;
+ *type = G_FILE_ATTRIBUTE_TYPE_STRINGV;
+ value->ptr = strv;
+ }
+ else
+ goto error;
- dbus_message_iter_recurse (&variant_iter, &cstring_iter);
- dbus_message_iter_get_fixed_array (&cstring_iter,
- &str, &n_elements);
- value->ptr = g_strndup (str, n_elements);
+ break;
+ case DBUS_TYPE_BYTE:
+ dbus_message_iter_get_basic (&variant_iter, &byte);
+ *type = G_FILE_ATTRIBUTE_TYPE_INVALID;
break;
case DBUS_TYPE_BOOLEAN:
dbus_message_iter_get_basic (&variant_iter, &dbus_bool);
diff --git a/common/gvfsfileinfo.c b/common/gvfsfileinfo.c
index df563cc7..aef5bd50 100644
--- a/common/gvfsfileinfo.c
+++ b/common/gvfsfileinfo.c
@@ -45,6 +45,25 @@ put_string (GDataOutputStream *out,
g_data_output_stream_put_string (out, str, NULL, NULL);
}
+static void
+put_stringv (GDataOutputStream *out,
+ char **strv)
+{
+ int len, i;
+
+ len = g_strv_length (strv);
+ if (len > G_MAXUINT16)
+ {
+ g_warning ("GFileInfo stringv to large, (%d elements)\n", (int)len);
+ len = 0;
+ }
+
+ g_data_output_stream_put_uint16 (out, len,
+ NULL, NULL);
+ for (i = 0; i < len; i++)
+ put_string (out, strv[i]);
+}
+
static char *
read_string (GDataInputStream *in)
{
@@ -58,6 +77,21 @@ read_string (GDataInputStream *in)
return str;
}
+static char **
+read_stringv (GDataInputStream *in)
+{
+ int len, i;
+ char **strv;
+
+ len = g_data_input_stream_read_uint16 (in, NULL, NULL);
+
+ strv = g_new (char *, len + 1);
+ for (i = 0; i < len; i++)
+ strv[i] = read_string (in);
+ strv[i] = NULL;
+ return strv;
+}
+
char *
gvfs_file_info_marshal (GFileInfo *info,
gsize *size)
@@ -103,6 +137,9 @@ gvfs_file_info_marshal (GFileInfo *info,
case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING:
put_string (out, g_file_info_get_attribute_byte_string (info, attr));
break;
+ case G_FILE_ATTRIBUTE_TYPE_STRINGV:
+ put_stringv (out, g_file_info_get_attribute_stringv (info, attr));
+ break;
case G_FILE_ATTRIBUTE_TYPE_BOOLEAN:
g_data_output_stream_put_byte (out,
g_file_info_get_attribute_boolean (info, attr),
@@ -174,7 +211,7 @@ gvfs_file_info_demarshal (char *data,
GInputStream *memstream;
GDataInputStream *in;
GFileInfo *info;
- char *attr, *str;
+ char *attr, *str, **strv;
GFileAttributeType type;
GFileAttributeStatus status;
GObject *obj;
@@ -208,6 +245,11 @@ gvfs_file_info_demarshal (char *data,
g_file_info_set_attribute_byte_string (info, attr, str);
g_free (str);
break;
+ case G_FILE_ATTRIBUTE_TYPE_STRINGV:
+ strv = read_stringv (in);
+ g_file_info_set_attribute_stringv (info, attr, strv);
+ g_strfreev (strv);
+ break;
case G_FILE_ATTRIBUTE_TYPE_BOOLEAN:
g_file_info_set_attribute_boolean (info, attr,
g_data_input_stream_read_byte (in,
@@ -261,6 +303,7 @@ gvfs_file_info_demarshal (char *data,
g_object_unref (obj);
break;
case G_FILE_ATTRIBUTE_TYPE_INVALID:
+ break;
default:
g_warning ("Unsupported GFileInfo attribute type %d\n", type);
g_free (attr);