Add varargs function: secret_schema_new vs. secret_schema_newv
authorStef Walter <stefw@gnome.org>
Thu, 28 Jun 2012 08:36:38 +0000 (10:36 +0200)
committerStef Walter <stefw@gnome.org>
Thu, 28 Jun 2012 08:36:38 +0000 (10:36 +0200)
 * 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
library/secret-password.c
library/secret-schema.c
library/secret-schema.h

index 98de4c8edc2ad849dd458c8ddc5442b183e2619c..584bf3096189f45f2284903267336e0f9f595356 100644 (file)
@@ -123,6 +123,7 @@ SecretSchemaFlags
 SecretSchemaAttribute
 SecretSchemaAttributeType
 secret_schema_new
+secret_schema_newv
 secret_schema_ref
 secret_schema_unref
 <SUBSECTION Standard>
index 093530f12a16bc5e58635cacdb7f34cfb1e17d2f..1ca60442959358a7f2384a353bd9a6f944ecae84 100644 (file)
@@ -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
index e56b54ab49c0aafdf567b80867a61eb89628546a..f625b996c9a59d1faace84ba8c3dcbadfa87b425 100644 (file)
@@ -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)) {
@@ -225,6 +228,67 @@ secret_schema_new (const gchar *name,
        return schema;
 }
 
+/**
+ * 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
index 6431acd0977019405460e61f6c4bc6dd00e28d36..ccbf5c949958e7e498593299c7aca37003b3bd4f 100644 (file)
@@ -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);