From cec740fea9a7ddec75cd625f86c03827e098326c Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Thu, 20 Jun 2013 12:11:27 +0200 Subject: [PATCH] Add secret_value_get_text() function to return NULL terminated secret --- docs/reference/libsecret/libsecret-sections.txt | 1 + libsecret/secret-value.c | 22 ++++++++++++++++++++++ libsecret/secret-value.h | 2 ++ 3 files changed, 25 insertions(+) diff --git a/docs/reference/libsecret/libsecret-sections.txt b/docs/reference/libsecret/libsecret-sections.txt index f8a9c1b..34045bc 100644 --- a/docs/reference/libsecret/libsecret-sections.txt +++ b/docs/reference/libsecret/libsecret-sections.txt @@ -296,6 +296,7 @@ SecretValue secret_value_new secret_value_new_full secret_value_get +secret_value_get_text secret_value_get_content_type secret_value_ref secret_value_unref diff --git a/libsecret/secret-value.c b/libsecret/secret-value.c index cbfdf6b..64130e0 100644 --- a/libsecret/secret-value.c +++ b/libsecret/secret-value.c @@ -44,6 +44,8 @@ * Stability: Unstable */ +static gboolean is_password_value (SecretValue *value); + /** * SecretValue: * @@ -170,6 +172,26 @@ secret_value_get (SecretValue *value, } /** + * secret_value_get_text: + * @value: the value + * + * Get the secret data in the #SecretValue if it contains a textual + * value. The content type must be text/plain. + * + * Returns: (allow-none): the content type + */ +const gchar * +secret_value_get_text (SecretValue *value) +{ + g_return_val_if_fail (value, NULL); + + if (!is_password_value (value)) + return NULL; + + return value->secret; +} + +/** * secret_value_get_content_type: * @value: the value * diff --git a/libsecret/secret-value.h b/libsecret/secret-value.h index 08bd88b..baaff34 100644 --- a/libsecret/secret-value.h +++ b/libsecret/secret-value.h @@ -43,6 +43,8 @@ SecretValue * secret_value_new_full (gchar *secret, const gchar * secret_value_get (SecretValue *value, gsize *length); +const gchar * secret_value_get_text (SecretValue *value); + const gchar * secret_value_get_content_type (SecretValue *value); SecretValue * secret_value_ref (SecretValue *value); -- 2.7.4