[grilo] core: Add binary support in GrlConfig
- From: Juan A. Suarez Romero <jasuarez src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo] core: Add binary support in GrlConfig
- Date: Thu, 3 Feb 2011 12:07:35 +0000 (UTC)
commit b0a0c883a436f4367472b6c143053110e40d5e6f
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date: Thu Jan 20 11:11:53 2011 +0000
core: Add binary support in GrlConfig
Add grl_config_get/set_binary so configurations allow binary data.
Based on work by Fabien Lebaillif.
Signed-off-by: Juan A. Suarez Romero <jasuarez igalia com>
src/data/grl-config.c | 42 ++++++++++++++++++++++++++++++++++++++++++
src/data/grl-config.h | 3 +++
2 files changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/src/data/grl-config.c b/src/data/grl-config.c
index 7c92b98..86bf88d 100644
--- a/src/data/grl-config.c
+++ b/src/data/grl-config.c
@@ -118,6 +118,9 @@ grl_config_new (const gchar *plugin, const gchar *source)
void
grl_config_set (GrlConfig *config, const gchar *param, const GValue *value)
{
+ GByteArray *array;
+ gchar *encoded;
+
g_return_if_fail (GRL_IS_CONFIG (config));
switch (G_VALUE_TYPE (value)) {
@@ -141,6 +144,14 @@ grl_config_set (GrlConfig *config, const gchar *param, const GValue *value)
g_value_get_boolean (value));
break;
+ case G_TYPE_BOXED:
+ array = g_value_get_boxed(value);
+ encoded = g_base64_encode ((const guchar *) array, array->len);
+ g_key_file_set_string (config->priv->config, GROUP_NAME, param,
+ encoded);
+ g_free (encoded);
+ break;
+
default:
g_return_if_reached ();
break;
@@ -172,6 +183,14 @@ grl_config_set_boolean (GrlConfig *config, const gchar *param, gboolean value)
g_key_file_set_boolean (config->priv->config, GROUP_NAME, param, value);
}
+void
+grl_config_set_binary (GrlConfig *config, const gchar *param, const guint8 *blob, gsize size)
+{
+ gchar *encoded = g_base64_encode (blob, size);
+ g_key_file_set_string (config->priv->config, GROUP_NAME, param, encoded);
+ g_free (encoded);
+}
+
gchar *
grl_config_get_string (GrlConfig *config, const gchar *param)
{
@@ -201,6 +220,29 @@ grl_config_get_boolean (GrlConfig *config, const gchar *param)
return g_key_file_get_boolean (config->priv->config, GROUP_NAME, param, NULL);
}
+guint8 *
+grl_config_get_binary (GrlConfig *config, const gchar *param, gsize *size)
+{
+ gchar *encoded;
+ gsize s;
+ guint8 *binary;
+
+ g_return_val_if_fail (GRL_IS_CONFIG (config), NULL);
+
+ encoded = g_key_file_get_string (config->priv->config, GROUP_NAME, param, NULL);
+ if (!encoded) {
+ return NULL;
+ }
+
+ binary = g_base64_decode (encoded, &s);
+ g_free (encoded);
+ if (size) {
+ *size = s;
+ }
+
+ return binary;
+}
+
/**
* grl_config_set_plugin:
* @config: the config instance
diff --git a/src/data/grl-config.h b/src/data/grl-config.h
index 647a1da..0f0697a 100644
--- a/src/data/grl-config.h
+++ b/src/data/grl-config.h
@@ -140,6 +140,7 @@ void grl_config_set_float (GrlConfig *config, const gchar *param, gfloat value);
void grl_config_set_boolean (GrlConfig *config, const gchar *param, gboolean value);
+void grl_config_set_binary (GrlConfig *config, const gchar *param, const guint8 *blob, gsize size);
gchar *grl_config_get_string (GrlConfig *config, const gchar *param);
@@ -149,6 +150,8 @@ gfloat grl_config_get_float (GrlConfig *config, const gchar *param);
gboolean grl_config_get_boolean (GrlConfig *config, const gchar *param);
+guint8 *grl_config_get_binary (GrlConfig *config, const gchar *param, gsize *size);
+
gboolean grl_config_has_param (GrlConfig *config, const gchar *param);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]