diff options
author | David Zeuthen <davidz@redhat.com> | 2009-05-26 11:11:13 -0400 |
---|---|---|
committer | David Zeuthen <davidz@redhat.com> | 2009-05-26 11:11:13 -0400 |
commit | a85e7d7936ed27080355076ed127204fa136daed (patch) | |
tree | 0ee415d9e6564f691fec1804745878b847790bd7 | |
parent | 028e1aa51e4df5655f7cf57824dcc5f20823e19f (diff) | |
download | polkit-a85e7d7936ed27080355076ed127204fa136daed.tar.gz |
Forgot to add source for PolkitDetails
-rw-r--r-- | src/polkit/polkitdetails.c | 149 | ||||
-rw-r--r-- | src/polkit/polkitdetails.h | 58 |
2 files changed, 207 insertions, 0 deletions
diff --git a/src/polkit/polkitdetails.c b/src/polkit/polkitdetails.c new file mode 100644 index 0000000..b263194 --- /dev/null +++ b/src/polkit/polkitdetails.c @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2008 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: David Zeuthen <davidz@redhat.com> + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <string.h> +#include "polkitimplicitauthorization.h" +#include "polkitdetails.h" + +#include "polkitprivate.h" + +/** + * SECTION:polkitdetails + * @title: PolkitDetails + * @short_description: Details + * + * An object used for passing details around. + */ + +struct _PolkitDetails +{ + GObject parent_instance; + + GHashTable *hash; +}; + +struct _PolkitDetailsClass +{ + GObjectClass parent_class; +}; + +G_DEFINE_TYPE (PolkitDetails, polkit_details, G_TYPE_OBJECT); + +static void +polkit_details_init (PolkitDetails *details) +{ +} + +static void +polkit_details_finalize (GObject *object) +{ + PolkitDetails *details; + + details = POLKIT_DETAILS (object); + + g_hash_table_unref (details->hash); + + if (G_OBJECT_CLASS (polkit_details_parent_class)->finalize != NULL) + G_OBJECT_CLASS (polkit_details_parent_class)->finalize (object); +} + +static void +polkit_details_class_init (PolkitDetailsClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->finalize = polkit_details_finalize; +} + +PolkitDetails * +polkit_details_new (void) +{ + PolkitDetails *details; + + details = POLKIT_DETAILS (g_object_new (POLKIT_TYPE_DETAILS, NULL)); + + return details; +} + +PolkitDetails * +polkit_details_new_for_hash (GHashTable *hash) +{ + PolkitDetails *details; + + details = POLKIT_DETAILS (g_object_new (POLKIT_TYPE_DETAILS, NULL)); + if (hash != NULL) + details->hash = g_hash_table_ref (hash); + + return details; +} + +GHashTable * +polkit_details_get_hash (PolkitDetails *details) +{ + return details->hash; +} + +const gchar * +polkit_details_lookup (PolkitDetails *details, + const gchar *key) +{ + if (details->hash == NULL) + return NULL; + else + return g_hash_table_lookup (details->hash, key); +} + +void +polkit_details_insert (PolkitDetails *details, + const gchar *key, + const gchar *value) +{ + if (details->hash == NULL) + details->hash = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + g_free); + g_hash_table_insert (details->hash, g_strdup (key), g_strdup (value)); +} + +gchar ** +polkit_details_get_keys (PolkitDetails *details) +{ + GList *keys, *l; + gchar **ret; + guint n; + + if (details->hash == NULL) + return NULL; + + keys = g_hash_table_get_keys (details->hash); + ret = g_new0 (gchar*, g_list_length (keys) + 1); + for (l = keys, n = 0; l != NULL; l = l->next, n++) + ret[n] = g_strdup (l->data); + + g_list_free (keys); + + return ret; +} diff --git a/src/polkit/polkitdetails.h b/src/polkit/polkitdetails.h new file mode 100644 index 0000000..ea2b425 --- /dev/null +++ b/src/polkit/polkitdetails.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2008 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * 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., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: David Zeuthen <davidz@redhat.com> + */ + +#if !defined (_POLKIT_COMPILATION) && !defined(_POLKIT_INSIDE_POLKIT_H) +#error "Only <polkit/polkit.h> can be included directly, this file may disappear or change contents." +#endif + +#ifndef __POLKIT_DETAILS_H +#define __POLKIT_DETAILS_H + +#include <glib-object.h> +#include <gio/gio.h> +#include <polkit/polkittypes.h> + +G_BEGIN_DECLS + +#define POLKIT_TYPE_DETAILS (polkit_details_get_type()) +#define POLKIT_DETAILS(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_DETAILS, PolkitDetails)) +#define POLKIT_DETAILS_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), POLKIT_TYPE_DETAILS, PolkitDetailsClass)) +#define POLKIT_DETAILS_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_DETAILS, PolkitDetailsClass)) +#define POLKIT_IS_DETAILS(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_DETAILS)) +#define POLKIT_IS_DETAILS_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_DETAILS)) + +#if 0 +typedef struct _PolkitDetails PolkitDetails; +#endif +typedef struct _PolkitDetailsClass PolkitDetailsClass; + +GType polkit_details_get_type (void) G_GNUC_CONST; +PolkitDetails *polkit_details_new (void); +const gchar *polkit_details_lookup (PolkitDetails *details, + const gchar *key); +void polkit_details_insert (PolkitDetails *details, + const gchar *key, + const gchar *value); +gchar **polkit_details_get_keys (PolkitDetails *details); + +G_END_DECLS + +#endif /* __POLKIT_DETAILS_H */ |