[gnome-keyring/gnome-3-0] Use full interface.Property form for CreateCollection and CreateItem



commit eeeddb5760050ef3ffe39925737982c309c53f9b
Author: Stef Walter <stefw collabora co uk>
Date:   Sat Mar 19 15:59:52 2011 +0100

    Use full interface.Property form for CreateCollection and CreateItem
    
    This is a change in the spec so that we can handle future extensibility
    on various interfaces properly.

 daemon/dbus/gkd-secret-objects.c  |    2 +-
 daemon/dbus/gkd-secret-property.c |   25 +++++++++++++++++++------
 daemon/dbus/gkd-secret-property.h |    1 +
 daemon/dbus/gkd-secret-service.c  |    4 ++--
 4 files changed, 23 insertions(+), 9 deletions(-)
---
diff --git a/daemon/dbus/gkd-secret-objects.c b/daemon/dbus/gkd-secret-objects.c
index 4cfd4e7..7206af1 100644
--- a/daemon/dbus/gkd-secret-objects.c
+++ b/daemon/dbus/gkd-secret-objects.c
@@ -667,7 +667,7 @@ collection_method_create_item (GkdSecretObjects *self, GckObject *object, DBusMe
 		g_return_val_if_reached (NULL);
 	attrs = gck_attributes_new ();
 	dbus_message_iter_recurse (&iter, &array);
-	if (!gkd_secret_property_parse_all (&array, attrs)) {
+	if (!gkd_secret_property_parse_all (&array, SECRET_ITEM_INTERFACE, attrs)) {
 		reply = dbus_message_new_error (message, DBUS_ERROR_INVALID_ARGS,
 		                                "Invalid properties argument");
 		goto cleanup;
diff --git a/daemon/dbus/gkd-secret-property.c b/daemon/dbus/gkd-secret-property.c
index 8b2f65f..cd2104e 100644
--- a/daemon/dbus/gkd-secret-property.c
+++ b/daemon/dbus/gkd-secret-property.c
@@ -61,12 +61,24 @@ typedef enum _DataType {
  */
 
 static gboolean
-property_to_attribute (const gchar *prop_name, CK_ATTRIBUTE_TYPE *attr_type, DataType *data_type)
+property_to_attribute (const gchar *prop_name, const gchar *interface,
+                       CK_ATTRIBUTE_TYPE *attr_type, DataType *data_type)
 {
 	g_return_val_if_fail (prop_name, FALSE);
 	g_assert (attr_type);
 	g_assert (data_type);
 
+	/* If an interface is desired, check that it matches, and remove */
+	if (interface) {
+		if (!g_str_has_prefix (prop_name, interface))
+			return FALSE;
+
+		prop_name += strlen (interface);
+		if (prop_name[0] != '.')
+			return FALSE;
+		++prop_name;
+	}
+
 	if (g_str_equal (prop_name, "Label")) {
 		*attr_type = CKA_LABEL;
 		*data_type = DATA_TYPE_STRING;
@@ -458,11 +470,12 @@ gkd_secret_property_get_type (const gchar *property, CK_ATTRIBUTE_TYPE *type)
 	g_return_val_if_fail (property, FALSE);
 	g_return_val_if_fail (type, FALSE);
 
-	return property_to_attribute (property, type, &data_type);
+	return property_to_attribute (property, NULL, type, &data_type);
 }
 
 gboolean
-gkd_secret_property_parse_all (DBusMessageIter *array, GckAttributes *attrs)
+gkd_secret_property_parse_all (DBusMessageIter *array, const gchar *interface,
+                               GckAttributes *attrs)
 {
 	DBusMessageIter dict;
 	CK_ATTRIBUTE_TYPE attr_type;
@@ -476,12 +489,12 @@ gkd_secret_property_parse_all (DBusMessageIter *array, GckAttributes *attrs)
 	while (dbus_message_iter_get_arg_type (array) == DBUS_TYPE_DICT_ENTRY) {
 		dbus_message_iter_recurse (array, &dict);
 
-		/* Property name */
+		/* Property interface.name */
 		g_return_val_if_fail (dbus_message_iter_get_arg_type (&dict) == DBUS_TYPE_STRING, FALSE);
 		dbus_message_iter_get_basic (&dict, &name);
 		dbus_message_iter_next (&dict);
 
-		if (!property_to_attribute (name, &attr_type, &data_type))
+		if (!property_to_attribute (name, interface, &attr_type, &data_type))
 			return FALSE;
 
 		/* Property value */
@@ -549,7 +562,7 @@ gkd_secret_property_parse_variant (DBusMessageIter *iter, const gchar *property,
 	g_return_val_if_fail (iter, FALSE);
 	g_return_val_if_fail (property, FALSE);
 
-	if (!property_to_attribute (property, &attr_type, &data_type))
+	if (!property_to_attribute (property, NULL, &attr_type, &data_type))
 		return FALSE;
 
 	attr->type = attr_type;
diff --git a/daemon/dbus/gkd-secret-property.h b/daemon/dbus/gkd-secret-property.h
index e1059b3..d04c414 100644
--- a/daemon/dbus/gkd-secret-property.h
+++ b/daemon/dbus/gkd-secret-property.h
@@ -45,6 +45,7 @@ gboolean               gkd_secret_property_parse_fields           (DBusMessageIt
                                                                    GckAttribute *attr);
 
 gboolean               gkd_secret_property_parse_all              (DBusMessageIter *array,
+                                                                   const gchar *interface,
                                                                    GckAttributes *attrs);
 
 #endif /* __GKD_SECRET_PROPERTY_H__ */
diff --git a/daemon/dbus/gkd-secret-service.c b/daemon/dbus/gkd-secret-service.c
index 66263fa..dfd1b3e 100644
--- a/daemon/dbus/gkd-secret-service.c
+++ b/daemon/dbus/gkd-secret-service.c
@@ -409,7 +409,7 @@ service_method_create_collection (GkdSecretService *self, DBusMessage *message)
 		g_return_val_if_reached (NULL);
 	attrs = gck_attributes_new ();
 	dbus_message_iter_recurse (&iter, &array);
-	if (!gkd_secret_property_parse_all (&array, attrs)) {
+	if (!gkd_secret_property_parse_all (&array, SECRET_COLLECTION_INTERFACE, attrs)) {
 		gck_attributes_unref (attrs);
 		return dbus_message_new_error_printf (message, DBUS_ERROR_INVALID_ARGS,
 		                                      "Invalid properties");
@@ -676,7 +676,7 @@ service_method_create_with_master_password (GkdSecretService *self, DBusMessage
 		g_return_val_if_reached (NULL);
 	attrs = gck_attributes_new ();
 	dbus_message_iter_recurse (&iter, &array);
-	if (!gkd_secret_property_parse_all (&array, attrs)) {
+	if (!gkd_secret_property_parse_all (&array, SECRET_COLLECTION_INTERFACE, attrs)) {
 		gck_attributes_unref (attrs);
 		return dbus_message_new_error (message, DBUS_ERROR_INVALID_ARGS,
 		                               "Invalid properties argument");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]