mirror of
https://gitlab.gnome.org/GNOME/libsecret.git
synced 2024-12-22 04:38:55 +00:00
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
This commit is contained in:
parent
2ff021044a
commit
30c0afeab1
@ -123,6 +123,7 @@ SecretSchemaFlags
|
||||
SecretSchemaAttribute
|
||||
SecretSchemaAttributeType
|
||||
secret_schema_new
|
||||
secret_schema_newv
|
||||
secret_schema_ref
|
||||
secret_schema_unref
|
||||
<SUBSECTION Standard>
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user