[libsecret] Add varargs function: secret_schema_new vs. secret_schema_newv



commit 30c0afeab1ba1261b0778b2edb79548eed3165d3
Author: Stef Walter <stefw gnome org>
Date:   Thu Jun 28 10:36:38 2012 +0200

    Add varargs function: secret_schema_new vs. secret_schema_newv
    
     * Rename secret_schema_new to secret_schema_newv which
       accepts a GHashTable
     * Make secret_schema_new accept varargs similar to the
       password functions.
     * This is useful from vala which supports varargs

 docs/reference/libsecret/libsecret-sections.txt |    1 +
 library/secret-password.c                       |    2 +-
 library/secret-schema.c                         |   78 +++++++++++++++++++++--
 library/secret-schema.h                         |    6 ++-
 4 files changed, 78 insertions(+), 9 deletions(-)
---
diff --git a/docs/reference/libsecret/libsecret-sections.txt b/docs/reference/libsecret/libsecret-sections.txt
index 98de4c8..584bf30 100644
--- a/docs/reference/libsecret/libsecret-sections.txt
+++ b/docs/reference/libsecret/libsecret-sections.txt
@@ -123,6 +123,7 @@ SecretSchemaFlags
 SecretSchemaAttribute
 SecretSchemaAttributeType
 secret_schema_new
+secret_schema_newv
 secret_schema_ref
 secret_schema_unref
 <SUBSECTION Standard>
diff --git a/library/secret-password.c b/library/secret-password.c
index 093530f..1ca6044 100644
--- a/library/secret-password.c
+++ b/library/secret-password.c
@@ -112,7 +112,7 @@ on_store_connected (GObject *source,
 }
 
 /**
- * secret_password_store:
+ * secret_password_store: (skip)
  * @schema: the schema for attributes
  * @collection_path: (allow-none): the D-Bus object path of the collection where to store the secret
  * @label: label for the secret
diff --git a/library/secret-schema.c b/library/secret-schema.c
index e56b54a..f625b99 100644
--- a/library/secret-schema.c
+++ b/library/secret-schema.c
@@ -143,10 +143,10 @@ G_DEFINE_BOXED_TYPE (SecretSchemaAttribute, secret_schema_attribute,
                      schema_attribute_copy, schema_attribute_free);
 
 /**
- * secret_schema_new:
+ * secret_schema_newv:
  * @name: the dotted name of the schema
  * @flags: the flags for the schema
- * @attributes: (element-type utf8 Secret.SchemaAttributeType): the attribute names and types of those attributes
+ * @attribute_names_and_types: (element-type utf8 Secret.SchemaAttributeType): the attribute names and types of those attributes
  *
  * Using this function is not normally necessary from C code. This is useful
  * for constructing #SecretSchema structures in bindings.
@@ -170,13 +170,15 @@ G_DEFINE_BOXED_TYPE (SecretSchemaAttribute, secret_schema_attribute,
  * that are not stored by the libsecret library. Other libraries such as libgnome-keyring
  * don't store the schema name.
  *
+ * Rename to: secret_schema_new
+ *
  * Returns: (transfer full): the new schema, which should be unreferenced with
  *          secret_schema_unref() when done
  */
 SecretSchema *
-secret_schema_new (const gchar *name,
-                   SecretSchemaFlags flags,
-                   GHashTable *attributes)
+secret_schema_newv (const gchar *name,
+                    SecretSchemaFlags flags,
+                    GHashTable *attribute_names_and_types)
 {
 	SecretSchema *schema;
 	GHashTableIter iter;
@@ -187,14 +189,15 @@ secret_schema_new (const gchar *name,
 	gint ind = 0;
 
 	g_return_val_if_fail (name != NULL, NULL);
+	g_return_val_if_fail (attribute_names_and_types != NULL, NULL);
 
 	schema = g_slice_new0 (SecretSchema);
 	schema->name = g_strdup (name);
 	schema->flags = flags;
 	schema->reserved = 1;
 
-	if (attributes) {
-		g_hash_table_iter_init (&iter, attributes);
+	if (attribute_names_and_types) {
+		g_hash_table_iter_init (&iter, attribute_names_and_types);
 		while (g_hash_table_iter_next (&iter, &key, &value)) {
 
 			if (ind >= G_N_ELEMENTS (schema->attributes)) {
@@ -226,6 +229,67 @@ secret_schema_new (const gchar *name,
 }
 
 /**
+ * secret_schema_new: (skip)
+ * @name: the dotted name of the schema
+ * @flags: the flags for the schema
+ * @...: the attribute names and types, terminated with %NULL
+ *
+ * Using this function is not normally necessary from C code.
+ *
+ * A schema represents a set of attributes that are stored with an item. These
+ * schemas are used for interoperability between various services storing the
+ * same types of items.
+ *
+ * Each schema has an @name like "org.gnome.keyring.NetworkPassword", and
+ * defines a set of attributes names, and types (string, integer, boolean) for
+ * those attributes.
+ *
+ * The variable argument list should contain pairs of a) The attribute name as
+ * a null-terminated string, followed by b) integers from the
+ * #SecretSchemaAttributeType enumeration, representing the attribute type for
+ * each attribute name. The list of attribtues should be terminated with a %NULL.
+ *
+ * Normally when looking up passwords only those with matching schema names are
+ * returned. If the schema @flags contain the %SECRET_SCHEMA_DONT_MATCH_NAME flag,
+ * then lookups will not check that the schema name matches that on the item, only
+ * the schema's attributes are matched. This is useful when you are looking up items
+ * that are not stored by the libsecret library. Other libraries such as libgnome-keyring
+ * don't store the schema name.
+ *
+ * Returns: (transfer full): the new schema, which should be unreferenced with
+ *          secret_schema_unref() when done
+ */
+SecretSchema *
+secret_schema_new (const gchar *name,
+                   SecretSchemaFlags flags,
+                   ...)
+{
+	SecretSchemaAttributeType type;
+	GHashTable *attributes;
+	SecretSchema *schema;
+	const gchar *attribute;
+	va_list va;
+
+	g_return_val_if_fail (name != NULL, NULL);
+
+	va_start (va, flags);
+	attributes = g_hash_table_new (g_str_hash, g_str_equal);
+
+	while ((attribute = va_arg (va, const gchar *)) != NULL) {
+		type = va_arg (va, SecretSchemaAttributeType);
+		g_hash_table_insert (attributes, (gpointer *)attribute,
+		                     GINT_TO_POINTER (type));
+	}
+
+	schema = secret_schema_newv (name, flags, attributes);
+
+	g_hash_table_unref (attributes);
+	va_end (va);
+
+	return schema;
+}
+
+/**
  * secret_schema_ref:
  * @schema: the schema to reference
  *
diff --git a/library/secret-schema.h b/library/secret-schema.h
index 6431acd..ccbf5c9 100644
--- a/library/secret-schema.h
+++ b/library/secret-schema.h
@@ -60,7 +60,11 @@ GType             secret_schema_get_type           (void) G_GNUC_CONST;
 
 SecretSchema *    secret_schema_new                (const gchar *name,
                                                     SecretSchemaFlags flags,
-                                                    GHashTable *attributes);
+                                                    ...) G_GNUC_NULL_TERMINATED;
+
+SecretSchema *    secret_schema_newv               (const gchar *name,
+                                                    SecretSchemaFlags flags,
+                                                    GHashTable *attribute_names_and_types);
 
 SecretSchema *    secret_schema_ref                (SecretSchema *schema);
 



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