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



commit b738c9f7878dd745355b6b0eb826799d73fc8e64
Author: Philip Withnall <withnall endlessm com>
Date:   Fri Sep 15 18:25:26 2017 +0100

    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

 docs/reference/libsecret/libsecret-sections.txt |    2 +
 libsecret/secret-schemas.c                      |   30 +++++++++++++++++++++-
 libsecret/secret-schemas.h                      |   19 ++++++++++++++
 3 files changed, 49 insertions(+), 2 deletions(-)
---
diff --git a/docs/reference/libsecret/libsecret-sections.txt b/docs/reference/libsecret/libsecret-sections.txt
index 1870dbf..de28b3b 100644
--- a/docs/reference/libsecret/libsecret-sections.txt
+++ b/docs/reference/libsecret/libsecret-sections.txt
@@ -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
diff --git a/libsecret/secret-schemas.c b/libsecret/secret-schemas.c
index 16f120e..7f93fc7 100644
--- a/libsecret/secret-schemas.c
+++ b/libsecret/secret-schemas.c
@@ -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 ();
+       }
+}
diff --git a/libsecret/secret-schemas.h b/libsecret/secret-schemas.h
index e4fc793..c78a001 100644
--- a/libsecret/secret-schemas.h
+++ b/libsecret/secret-schemas.h
@@ -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___ */


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