lib/schemas: Add secret_get_schema() accessor for SECRET_SCHEMA_*s

The SECRET_SCHEMA_* extern structs are not introspectable; add a new
accessor function which takes an enum and returns a struct, which is
introspectable.

Mark the old extern structs as (skip), but don’t deprecate them because
they’re still useful from C (if unconventional).

Signed-off-by: Philip Withnall <withnall@endlessm.com>

https://bugzilla.gnome.org/show_bug.cgi?id=697681
This commit is contained in:
Philip Withnall 2017-09-15 18:25:26 +01:00
parent d3ac1c1834
commit b738c9f787
3 changed files with 49 additions and 2 deletions

View File

@ -150,6 +150,8 @@ secret_schema_new
secret_schema_newv
secret_schema_ref
secret_schema_unref
SecretSchemaType
secret_get_schema
<SUBSECTION Standard>
secret_schema_get_type
secret_schema_attribute_get_type

View File

@ -15,9 +15,10 @@
#include "config.h"
#include "secret-schema.h"
#include "secret-schemas.h"
/**
* SECRET_SCHEMA_NOTE:
* SECRET_SCHEMA_NOTE: (skip)
*
* A predefined schema for personal passwords stored by the user in the
* password manager. This schema has no attributes, and the items are not
@ -39,7 +40,7 @@ static const SecretSchema note_schema = {
const SecretSchema * SECRET_SCHEMA_NOTE = &note_schema;
/**
* SECRET_SCHEMA_COMPAT_NETWORK:
* SECRET_SCHEMA_COMPAT_NETWORK: (skip)
*
* A predefined schema that is compatible with items stored via the
* libgnome-keyring 'network password' functions. This is meant to be used by
@ -85,3 +86,28 @@ static const SecretSchema network_schema = {
};
const SecretSchema * SECRET_SCHEMA_COMPAT_NETWORK = &network_schema;
/**
* secret_get_schema:
* @type: type of schema to get
*
* Get a secret storage schema of the given @type.
*
* C code may access the schemas (such as %SECRET_SCHEMA_NOTE) directly, but
* language bindings cannot, and must use this accessor.
*
* Returns: (transfer none): schema type
* Since: 0.18.6
*/
const SecretSchema *
secret_get_schema (SecretSchemaType type)
{
switch (type) {
case SECRET_SCHEMA_TYPE_NOTE:
return SECRET_SCHEMA_NOTE;
case SECRET_SCHEMA_TYPE_COMPAT_NETWORK:
return SECRET_SCHEMA_COMPAT_NETWORK;
default:
g_assert_not_reached ();
}
}

View File

@ -37,6 +37,25 @@ extern const SecretSchema * SECRET_SCHEMA_NOTE;
extern const SecretSchema * SECRET_SCHEMA_COMPAT_NETWORK;
/**
* SecretSchemaType:
* @SECRET_SCHEMA_TYPE_NOTE: Personal passwords; see %SECRET_SCHEMA_NOTE
* @SECRET_SCHEMA_TYPE_COMPAT_NETWORK: Network passwords from older
* libgnome-keyring storage; see %SECRET_SCHEMA_COMPAT_NETWORK
*
* Different types of schemas for storing secrets, intended for use with
* secret_get_schema().
*
* Since: 0.18.6
*/
typedef enum
{
SECRET_SCHEMA_TYPE_NOTE,
SECRET_SCHEMA_TYPE_COMPAT_NETWORK,
} SecretSchemaType;
const SecretSchema *secret_get_schema (SecretSchemaType type);
G_END_DECLS
#endif /* __SECRET_SCHEMAS_H___ */