new files with some utilities
authorAlexander Akimov <ext-alexander.akimov@nokia.com>
Tue, 13 Apr 2010 09:43:06 +0000 (12:43 +0300)
committerAlexander Akimov <ext-alexander.akimov@nokia.com>
Tue, 13 Apr 2010 09:43:06 +0000 (12:43 +0300)
libsignon-glib/signon-utils.c [new file with mode: 0644]
libsignon-glib/signon-utils.h [new file with mode: 0644]

diff --git a/libsignon-glib/signon-utils.c b/libsignon-glib/signon-utils.c
new file mode 100644 (file)
index 0000000..dce8db4
--- /dev/null
@@ -0,0 +1,59 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of libsignon-glib
+ *
+ * Copyright (C) 2009-2010 Nokia Corporation.
+ *
+ * Contact: Alberto Mardegan <alberto.mardegan@nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#include "signon-utils.h"
+
+static void signon_copy_gvalue (gchar *key,
+                                GValue *value,
+                                GHashTable *dest)
+{
+    GValue *copy_value = g_new0 (GValue, 1);
+    g_value_init (copy_value, value->g_type);
+    g_value_copy (value, copy_value);
+
+    g_hash_table_insert (dest, g_strdup(key), copy_value);
+}
+
+static void signon_free_gvalue (gpointer val)
+{
+    g_return_if_fail (G_IS_VALUE(val));
+
+    GValue* value = (GValue*)val;
+    g_value_unset (value);
+    g_free (value);
+}
+
+GHashTable *signon_copy_variant_map (const GHashTable *old_map)
+{
+    GHashTable* new_map = g_hash_table_new_full (g_str_hash,
+                                                 g_str_equal,
+                                                 g_free,
+                                                 signon_free_gvalue);
+
+    g_hash_table_foreach ((GHashTable*)old_map,
+                          (GHFunc)signon_copy_gvalue,
+                          (gpointer)new_map);
+
+   return new_map;
+}
+
diff --git a/libsignon-glib/signon-utils.h b/libsignon-glib/signon-utils.h
new file mode 100644 (file)
index 0000000..7d9465f
--- /dev/null
@@ -0,0 +1,31 @@
+/* vi: set et sw=4 ts=4 cino=t0,(0: */
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of libsignon-glib
+ *
+ * Copyright (C) 2009-2010 Nokia Corporation.
+ *
+ * Contact: Alberto Mardegan <alberto.mardegan@nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+#ifndef _SIGNON_UTILS_H_
+#define _SIGNON_UTILS_H_
+
+#include <glib-object.h>
+
+GHashTable *signon_copy_variant_map (const GHashTable *old_map);
+
+#endif //_SIGNON_UTILS_H_