"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
- <!-- User defined struct for Subjects -->
+ <!-- Subject struct -->
<annotation name="org.gtk.EggDBus.DeclareStruct" value="Subject">
- <annotation name="org.gtk.EggDBus.Struct.Signature" value="(sa{sv})"/>
- <!-- element 0: string: the subject type; known values: "unix-user", "unix-group", "unix-process" -->
+ <annotation name="org.gtk.EggDBus.Struct.Member" value="s:subject_kind">
+ <annotation name="org.gtk.EggDBus.DocString" value="Kind of subject"/>
+ </annotation>
- <!-- element 1: map<string,any>: key/value pairs depending on the subject type -->
+ <annotation name="org.gtk.EggDBus.Struct.Member" value="a{sv}:subject_details">
+ <annotation name="org.gtk.EggDBus.DocString" value="Details about the subject"/>
+ </annotation>
- <!-- TODO: document values in hash table for each subject type-->
+ <!-- TODO: document values in hash map for each subject type-->
</annotation>
- <!-- User defined struct for ActionDescription -->
+ <!-- ActionDescription struct -->
<annotation name="org.gtk.EggDBus.DeclareStruct" value="ActionDescription">
- <annotation name="org.gtk.EggDBus.Struct.Signature" value="(ssssssa{ss})"/>
- <!-- element 0: string: action-id -->
- <!-- element 1: string: description -->
- <!-- element 2: string: message -->
- <!-- element 3: string: vendor name -->
- <!-- element 4: string: vendor url -->
- <!-- element 5: string: icon name -->
- <!-- element 6: map<string,string>: annotations -->
+ <annotation name="org.gtk.EggDBus.Struct.Member" value="s:action_id">
+ <annotation name="org.gtk.EggDBus.DocString" value="Action Identifier"/>
+ </annotation>
+ <annotation name="org.gtk.EggDBus.Struct.Member" value="s:description">
+ <annotation name="org.gtk.EggDBus.DocString" value="Action Description"/>
+ </annotation>
+ <annotation name="org.gtk.EggDBus.Struct.Member" value="s:message">
+ <annotation name="org.gtk.EggDBus.DocString" value="Action Message"/>
+ </annotation>
+ <annotation name="org.gtk.EggDBus.Struct.Member" value="s:vendor_name">
+ <annotation name="org.gtk.EggDBus.DocString" value="Vendor Name"/>
+ </annotation>
+ <annotation name="org.gtk.EggDBus.Struct.Member" value="s:vendor_url">
+ <annotation name="org.gtk.EggDBus.DocString" value="Vendor URL"/>
+ </annotation>
+ <annotation name="org.gtk.EggDBus.Struct.Member" value="s:icon_name">
+ <annotation name="org.gtk.EggDBus.DocString" value="Icon Name"/>
+ </annotation>
+ <annotation name="org.gtk.EggDBus.Struct.Member" value="a{ss}:annotations">
+ <annotation name="org.gtk.EggDBus.DocString" value="Annotations"/>
+ </annotation>
<!-- TODO: also include defaults -->
</annotation>
- <!-- User defined struct for AuthorizationClaim -->
+ <!-- AuthorizationClaim struct -->
<annotation name="org.gtk.EggDBus.DeclareStruct" value="AuthorizationClaim">
- <annotation name="org.gtk.EggDBus.Struct.Signature" value="((sa{sv})sa{ss})"/>
+ <annotation name="org.gtk.EggDBus.Struct.Member" value="(sa{sv}):subject">
+ <annotation name="org.gtk.EggDBus.DocString" value="Subject the claim is for"/>
+ </annotation>
- <!-- element 0: (sa{sv}): subject -->
- <!-- element 1: string: action-id -->
- <!-- element 2: map<string,string>: attributes -->
+ <annotation name="org.gtk.EggDBus.Struct.Member" value="s:action_id">
+ <annotation name="org.gtk.EggDBus.DocString" value="Action Identifier for the claim"/>
+ </annotation>
+
+ <annotation name="org.gtk.EggDBus.Struct.Member" value="a{ss}:attributes">
+ <annotation name="org.gtk.EggDBus.DocString" value="Attributes for the claim"/>
+ </annotation>
</annotation>
-DPACKAGE_LIB_DIR=\""$(libdir)"\" \
-D_POSIX_PTHREAD_SEMANTICS \
-D_REENTRANT \
+ -DEGG_DBUS_I_KNOW_API_IS_SUBJECT_TO_CHANGE \
$(NULL)
-BUILT_SOURCES = \
- polkitbindings.h polkitbindings.c \
- polkitbindingstypes.h \
- polkitauthority.h polkitauthority.c \
- polkiterror.h polkiterror.c \
- polkitbindingsmarshal.h polkitbindingsmarshal.c \
- polkitauthorizationresult.h polkitauthorizationresult.c \
- polkitbindingsmarshal.list \
- $(NULL)
+BUILT_SOURCES = \
+ _polkitactiondescription.c _polkitactiondescription.h \
+ _polkitauthority.c _polkitauthority.h \
+ _polkitauthorizationclaim.c _polkitauthorizationclaim.h \
+ _polkitauthorizationresult.c _polkitauthorizationresult.h \
+ _polkitbindings.c _polkitbindings.h \
+ _polkitbindingsmarshal.c _polkitbindingsmarshal.h \
+ _polkitbindingstypes.h \
+ _polkiterror.c _polkiterror.h \
+ _polkitsubject.c _polkitsubject.h \
+ $(NULL)
$(BUILT_SOURCES) : Makefile.am $(top_srcdir)/data/org.freedesktop.PolicyKit1.Authority.xml
- dbus2gobject \
- --namespace "Polkit" \
+ eggdbus-binding-tool \
+ --namespace "_Polkit" \
--dbus-namespace "org.freedesktop.PolicyKit1" \
--introspection-xml $(top_srcdir)/data/org.freedesktop.PolicyKit1.Authority.xml \
$(NULL)
libpolkit_gobject_1includedir=$(includedir)/polkit-1/polkit
-libpolkit_gobject_1include_HEADERS = \
- polkit.h \
- polkitauthoritystub.h \
- polkitactiondescription.h \
- polkitauthority.h \
- polkitauthorizationclaim.h \
- polkitauthorizationresult.h \
- polkiterror.h \
- polkitsubject.h \
- polkitbindings.h \
- polkitbindingstypes.h \
- polkitauthority.h \
+libpolkit_gobject_1include_HEADERS = \
+ polkit.h \
+ polkitactiondescription.h \
+ polkitauthority.h \
+ polkiterror.h \
$(NULL)
-libpolkit_gobject_1_la_SOURCES = \
- polkit.h \
- polkitauthoritystub.h polkitauthoritystub.c \
- polkitactiondescription.h polkitactiondescription.c \
- polkitauthorizationclaim.h polkitauthorizationclaim.c \
- polkitsubject.h polkitsubject.c \
- $(BUILT_SOURCES) \
+libpolkit_gobject_1_la_SOURCES = \
+ polkit.h \
+ $(BUILT_SOURCES) \
+ polkitactiondescription.c polkitactiondescription.h \
+ polkitauthority.c polkitauthority.h \
+ polkiterror.c polkiterror.h \
$(NULL)
libpolkit_gobject_1_la_CFLAGS = \
#define __POLKIT_H
#define _POLKIT_INSIDE_POLKIT_H 1
-#include <polkit/polkitbindings.h>
-#include <polkit/polkitauthoritystub.h>
-#include <polkit/polkiterror.h>
-#include <polkit/polkitsubject.h>
-#include <polkit/polkitauthorizationclaim.h>
-#include <polkit/polkitauthorizationresult.h>
#include <polkit/polkitactiondescription.h>
+#include <polkit/polkitauthority.h>
+#include <polkit/polkiterror.h>
#undef _POLKIT_INSIDE_POLKIT_H
#endif /* __POLKIT_H */
-
-
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
-#include <string.h>
-#include "polkitbindings.h"
+
#include "polkitactiondescription.h"
+#include "_polkitactiondescription.h"
+
+#include "polkitprivate.h"
/**
* SECTION:polkitactiondescription
* @title: PolkitActionDescription
- * @short_description: Descriptions of actions
+ * @short_description: Actions
*
- * The #PolkitActionDescription type is used to described registered PolicyKit actions.
+ * Encapsulates an action.
*/
-static void
-base_init (gpointer g_iface)
+struct _PolkitActionDescription
{
-}
+ GObject parent_instance;
+
+ _PolkitActionDescription *real;
+};
-GType
-polkit_action_description_get_type (void)
+struct _PolkitActionDescriptionClass
{
- static GType iface_type = 0;
+ GObjectClass parent_class;
+};
- if (iface_type == 0)
- {
- static const GTypeInfo info =
- {
- sizeof (PolkitActionDescriptionIface),
- base_init, /* base_init */
- NULL, /* base_finalize */
- NULL, /* class_init */
- NULL, /* class_finalize */
- NULL, /* class_data */
- 0, /* instance_size */
- 0, /* n_preallocs */
- NULL, /* instance_init */
- NULL /* value_table */
- };
-
- iface_type = g_type_register_static (G_TYPE_INTERFACE, "PolkitActionDescription", &info, 0);
-
- g_type_interface_add_prerequisite (iface_type, EGG_DBUS_TYPE_STRUCTURE);
- }
+G_DEFINE_TYPE (PolkitActionDescription, polkit_action_description, G_TYPE_OBJECT);
- return iface_type;
+static void
+polkit_action_description_init (PolkitActionDescription *action_description)
+{
}
-#define ACTION_DESCRIPTION_SIGNATURE "(ssssssa{ss})"
-
-/**
- * polkit_action_description_get_action_id:
- * @action_description: A #PolkitActionDescription.
- *
- * Gets the action identifer for @action_description.
- *
- * Returns: The action identifier for @action_description.
- */
-const gchar *
-polkit_action_description_get_action_id (PolkitActionDescription *action_description)
+static void
+polkit_action_description_finalize (GObject *object)
{
- const gchar *s;
+ PolkitActionDescription *action_description;
- g_return_val_if_fail (POLKIT_IS_ACTION_DESCRIPTION (action_description), NULL);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (action_description)), ACTION_DESCRIPTION_SIGNATURE) == 0, NULL);
+ action_description = POLKIT_ACTION_DESCRIPTION (object);
- egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (action_description),
- 0, &s,
- -1);
-
- return s;
+ g_object_unref (action_description->real);
}
-/**
- * polkit_action_description_get_description:
- * @action_description: A #PolkitActionDescription.
- *
- * Gets a human readable description of @action_description.
- *
- * Returns: The human readable description for @action_description or %NULL if not set.
- */
-const gchar *
-polkit_action_description_get_description (PolkitActionDescription *action_description)
+static void
+polkit_action_description_class_init (PolkitActionDescriptionClass *klass)
{
- const gchar *s;
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- g_return_val_if_fail (POLKIT_IS_ACTION_DESCRIPTION (action_description), NULL);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (action_description)), ACTION_DESCRIPTION_SIGNATURE) == 0, NULL);
-
- egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (action_description),
- 1, &s,
- -1);
-
- return strlen (s) > 0 ? s : NULL;
+ gobject_class->finalize = polkit_action_description_finalize;
}
-/**
- * polkit_action_description_get_message:
- * @action_description: A #PolkitActionDescription.
- *
- * Gets the message shown for @action_description.
- *
- * Returns: The message for @action_description or %NULL if not set.
- */
-const gchar *
-polkit_action_description_get_message (PolkitActionDescription *action_description)
+PolkitActionDescription *
+polkit_action_description_new_for_real (_PolkitActionDescription *real)
{
- const gchar *s;
+ PolkitActionDescription *action_description;
- g_return_val_if_fail (POLKIT_IS_ACTION_DESCRIPTION (action_description), NULL);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (action_description)), ACTION_DESCRIPTION_SIGNATURE) == 0, NULL);
+ action_description = POLKIT_ACTION_DESCRIPTION (g_object_new (POLKIT_TYPE_ACTION_DESCRIPTION, NULL));
+ action_description->real = g_object_ref (real);
- egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (action_description),
- 2, &s,
- -1);
+ return action_description;
+}
- return strlen (s) > 0 ? s : NULL;
+_PolkitActionDescription *
+polkit_action_description_get_real (PolkitActionDescription *action_description)
+{
+ return action_description->real;
}
-/**
- * polkit_action_description_get_vendor_name:
- * @action_description: A #PolkitActionDescription.
- *
- * Gets the name of the vendor for @action_description.
- *
- * Returns: The vendor of @action_description or %NULL if not set.
- */
-const gchar *
-polkit_action_description_get_vendor_name (PolkitActionDescription *action_description)
+const gchar *
+polkit_action_description_get_action_id (PolkitActionDescription *action_description)
{
- const gchar *s;
+ return _polkit_action_description_get_action_id (action_description->real);
+}
- g_return_val_if_fail (POLKIT_IS_ACTION_DESCRIPTION (action_description), NULL);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (action_description)), ACTION_DESCRIPTION_SIGNATURE) == 0, NULL);
+const gchar *
+polkit_action_description_get_description (PolkitActionDescription *action_description)
+{
+ return _polkit_action_description_get_description (action_description->real);
+}
- egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (action_description),
- 3, &s,
- -1);
+const gchar *
+polkit_action_description_get_message (PolkitActionDescription *action_description)
+{
+ return _polkit_action_description_get_message (action_description->real);
+}
- return strlen (s) > 0 ? s : NULL;
+const gchar *
+polkit_action_description_get_vendor_name (PolkitActionDescription *action_description)
+{
+ return _polkit_action_description_get_vendor_name (action_description->real);
}
-/**
- * polkit_action_description_get_vendor_url:
- * @action_description: A #PolkitActionDescription.
- *
- * Gets the vendor URL for @action_description.
- *
- * Returns: The vendor URL for @action_description or %NULL if not set.
- */
-const gchar *
+const gchar *
polkit_action_description_get_vendor_url (PolkitActionDescription *action_description)
{
- const gchar *s;
-
- g_return_val_if_fail (POLKIT_IS_ACTION_DESCRIPTION (action_description), NULL);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (action_description)), ACTION_DESCRIPTION_SIGNATURE) == 0, NULL);
-
- egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (action_description),
- 4, &s,
- -1);
-
- return strlen (s) > 0 ? s : NULL;
+ return _polkit_action_description_get_vendor_url (action_description->real);
}
-/**
- * polkit_action_description_get_icon:
- * @action_description: A #PolkitActionDescription.
- *
- * Gets the #GIcon for @action_description.
- *
- * Returns: A #GIcon (free with g_object_unref() when done with it) or %NULL if not set.
- */
GIcon *
polkit_action_description_get_icon (PolkitActionDescription *action_description)
{
- const gchar *s;
+ const gchar *icon_name;
GIcon *icon;
+ GError *error;
- g_return_val_if_fail (POLKIT_IS_ACTION_DESCRIPTION (action_description), NULL);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (action_description)), ACTION_DESCRIPTION_SIGNATURE) == 0, NULL);
-
- egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (action_description),
- 5, &s,
- -1);
+ icon_name = _polkit_action_description_get_icon_name (action_description->real);
- if (strlen (s) > 0)
+ error = NULL;
+ icon = g_icon_new_for_string (icon_name, &error);
+ if (icon_name == NULL)
{
- icon = NULL;
- }
- else
- {
- GError *error;
-
- error = NULL;
- icon = g_icon_new_for_string (s, &error);
- if (icon == NULL)
- {
- g_warning ("Error getting icon for action description: %s", error->message);
- g_error_free (error);
- }
+ g_warning ("polkit_action_description_get_icon: %s", error->message);
+ g_error_free (error);
}
return icon;
}
-
-/**
- * polkit_action_description_get_annotations:
- * @action_description: A #PolkitActionDescription.
- *
- * Gets the annotations for @action_description.
- *
- * Returns: A #GHashTable from strings to strings with the annotations
- * for @action_description. Do not destroy or unref this hash table;
- * it is owned by @action_description.
- */
-GHashTable *
-polkit_action_description_get_annotations (PolkitActionDescription *action_description)
-{
- GHashTable *hash;
-
- g_return_val_if_fail (POLKIT_IS_ACTION_DESCRIPTION (action_description), NULL);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (action_description)), ACTION_DESCRIPTION_SIGNATURE) == 0, NULL);
-
- egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (action_description),
- 6, &hash,
- -1);
-
- return hash;
-}
-
#ifndef __POLKIT_ACTION_DESCRIPTION_H
#define __POLKIT_ACTION_DESCRIPTION_H
-#include <sys/types.h>
-#include <unistd.h>
#include <glib-object.h>
-#include <polkit/polkitbindings.h>
+#include <gio/gio.h>
+#include <polkit/polkittypes.h>
G_BEGIN_DECLS
-#define POLKIT_TYPE_ACTION_DESCRIPTION (polkit_action_description_get_type())
-#define POLKIT_ACTION_DESCRIPTION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_ACTION_DESCRIPTION, PolkitActionDescription))
-#define POLKIT_IS_ACTION_DESCRIPTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_ACTION_DESCRIPTION))
-#define POLKIT_ACTION_DESCRIPTION_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE((o), POLKIT_TYPE_ACTION_DESCRIPTION, PolkitActionDescriptionIface))
+#define POLKIT_TYPE_ACTION_DESCRIPTION (polkit_action_description_get_type())
+#define POLKIT_ACTION_DESCRIPTION(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_ACTION_DESCRIPTION, PolkitActionDescription))
+#define POLKIT_ACTION_DESCRIPTION_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), POLKIT_TYPE_ACTION_DESCRIPTION, PolkitActionDescriptionClass))
+#define POLKIT_ACTION_DESCRIPTION_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_ACTION_DESCRIPTION, PolkitActionDescriptionClass))
+#define POLKIT_IS_ACTION_DESCRIPTION(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_ACTION_DESCRIPTION))
+#define POLKIT_IS_ACTION_DESCRIPTION_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_ACTION_DESCRIPTION))
#if 0
-typedef struct _PolkitActionDescription PolkitActionDescription; /* Dummy typedef */
+typedef struct _PolkitActionDescription PolkitActionDescription;
#endif
-typedef struct _PolkitActionDescriptionIface PolkitActionDescriptionIface;
-
-struct _PolkitActionDescriptionIface
-{
- GTypeInterface g_iface;
-};
+typedef struct _PolkitActionDescriptionClass PolkitActionDescriptionClass;
GType polkit_action_description_get_type (void) G_GNUC_CONST;
const gchar *polkit_action_description_get_action_id (PolkitActionDescription *action_description);
const gchar *polkit_action_description_get_vendor_name (PolkitActionDescription *action_description);
const gchar *polkit_action_description_get_vendor_url (PolkitActionDescription *action_description);
GIcon *polkit_action_description_get_icon (PolkitActionDescription *action_description);
-GHashTable *polkit_action_description_get_annotations (PolkitActionDescription *action_description);
G_END_DECLS
--- /dev/null
+/*
+ * 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 "polkitauthority.h"
+
+#include "polkitprivate.h"
+
+/**
+ * SECTION:polkitauthority
+ * @title: PolkitAuthority
+ * @short_description: Authority
+ *
+ * Checking claims.
+ */
+
+struct _PolkitAuthority
+{
+ GObject parent_instance;
+
+ EggDBusObjectProxy *authority_object_proxy;
+
+ _PolkitAuthority *real;
+};
+
+struct _PolkitAuthorityClass
+{
+ GObjectClass parent_class;
+
+};
+
+/* TODO: locking */
+
+static PolkitAuthority *the_authority = NULL;
+
+G_DEFINE_TYPE (PolkitAuthority, polkit_authority, G_TYPE_OBJECT);
+
+static void
+polkit_authority_init (PolkitAuthority *authority)
+{
+ EggDBusConnection *system_bus;
+
+ system_bus = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM);
+
+ authority->authority_object_proxy = egg_dbus_connection_get_object_proxy (system_bus,
+ "org.freedesktop.PolicyKit1",
+ "/org/freedesktop/PolicyKit1/Authority");
+
+ authority->real = _POLKIT_QUERY_INTERFACE_AUTHORITY (authority->authority_object_proxy);
+
+ g_object_unref (system_bus);
+}
+
+static void
+polkit_authority_finalize (GObject *object)
+{
+ PolkitAuthority *authority;
+
+ authority = POLKIT_AUTHORITY (object);
+
+ g_object_unref (authority->authority_object_proxy);
+
+ the_authority = NULL;
+}
+
+static void
+polkit_authority_class_init (PolkitAuthorityClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->finalize = polkit_authority_finalize;
+}
+
+PolkitAuthority *
+polkit_authority_get (void)
+{
+ if (the_authority != NULL)
+ goto out;
+
+ the_authority = POLKIT_AUTHORITY (g_object_new (POLKIT_TYPE_AUTHORITY, NULL));
+
+ out:
+ return the_authority;
+}
+
+GList *
+polkit_authority_enumerate_actions_sync (PolkitAuthority *authority,
+ const gchar *locale,
+ GCancellable *cancellable,
+ GError **error)
+{
+ EggDBusArraySeq *array_seq;
+ GList *result;
+ guint n;
+
+ result = NULL;
+
+ if (!_polkit_authority_enumerate_actions_sync (authority->real,
+ EGG_DBUS_CALL_FLAGS_NONE,
+ locale,
+ &array_seq,
+ cancellable,
+ error))
+ goto out;
+
+ for (n = 0; n < array_seq->size; n++)
+ {
+ _PolkitActionDescription *real_ad;
+
+ real_ad = array_seq->data.v_ptr[n];
+
+ result = g_list_prepend (result, polkit_action_description_new_for_real (real_ad));
+ }
+
+ result = g_list_reverse (result);
+
+ out:
+ return result;
+}
--- /dev/null
+/*
+ * 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>
+ */
+
+#ifndef __POLKIT_AUTHORITY_H
+#define __POLKIT_AUTHORITY_H
+
+#include <glib-object.h>
+#include <gio/gio.h>
+#include <polkit/polkittypes.h>
+
+G_BEGIN_DECLS
+
+#define POLKIT_TYPE_AUTHORITY (polkit_authority_get_type())
+#define POLKIT_AUTHORITY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_AUTHORITY, PolkitAuthority))
+#define POLKIT_AUTHORITY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), POLKIT_TYPE_AUTHORITY, PolkitAuthorityClass))
+#define POLKIT_AUTHORITY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_AUTHORITY, PolkitAuthorityClass))
+#define POLKIT_IS_AUTHORITY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_AUTHORITY))
+#define POLKIT_IS_AUTHORITY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_AUTHORITY))
+
+#if 0
+typedef struct _PolkitAuthority PolkitAuthority;
+#endif
+typedef struct _PolkitAuthorityClass PolkitAuthorityClass;
+
+GType polkit_authority_get_type (void) G_GNUC_CONST;
+
+PolkitAuthority *polkit_authority_get (void);
+
+GList *polkit_authority_enumerate_actions_sync (PolkitAuthority *authority,
+ const gchar *locale,
+ GCancellable *cancellable,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* __POLKIT_AUTHORITY_H */
+++ /dev/null
-/*
- * 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>
- */
-
-#include "config.h"
-#include "polkitauthoritystub.h"
-
-/* TODO: locking */
-
-static PolkitAuthority *the_authority = NULL;
-
-/**
- * polkit_authority_get:
- *
- * Gets the default authority for checking claims.
- *
- * Returns: A reference to a #PolkitAuthority instance. Call g_object_unref() when done with it
- **/
-PolkitAuthority *
-polkit_authority_get (void)
-{
- PolkitAuthority *authority;
-
- polkit_bindings_register_types (); /* TODO: use __attribute ((constructor)) */
-
- if (the_authority != NULL)
- {
- authority = g_object_ref (the_authority);
- }
- else
- {
- EggDBusConnection *connection;
-
- connection = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM);
- authority = POLKIT_AUTHORITY (egg_dbus_connection_get_proxy (connection,
- "org.freedesktop.PolicyKit1",
- "/org/freedesktop/PolicyKit1/Authority"));
-
- /* TODO: take a weak reference and set the_authority to NULL on destruction */
-
- /* TODO: unref connection since authority holds a reference? */
- }
-
- return authority;
-}
+++ /dev/null
-/*
- * 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>
- */
-
-#include "config.h"
-#include <string.h>
-#include "polkitauthorizationclaim.h"
-#include "polkitsubject.h"
-
-/**
- * SECTION:polkitauthorizationclaim
- * @title: PolkitAuthorizationClaim
- * @short_description: Authorization Claim
- *
- * Represents an authorization claim.
- */
-
-static void
-base_init (gpointer g_iface)
-{
-}
-
-GType
-polkit_authorization_claim_get_type (void)
-{
- static GType iface_type = 0;
-
- if (iface_type == 0)
- {
- static const GTypeInfo info =
- {
- sizeof (PolkitAuthorizationClaimIface),
- base_init, /* base_init */
- NULL, /* base_finalize */
- NULL, /* class_init */
- NULL, /* class_finalize */
- NULL, /* class_data */
- 0, /* instance_size */
- 0, /* n_preallocs */
- NULL, /* instance_init */
- NULL /* value_table */
- };
-
- iface_type = g_type_register_static (G_TYPE_INTERFACE, "PolkitAuthorizationClaim", &info, 0);
-
- g_type_interface_add_prerequisite (iface_type, EGG_DBUS_TYPE_STRUCTURE);
- }
-
- return iface_type;
-}
-
-#define AUTHORIZATION_CLAIM_SIGNATURE "((sa{sv})sa{ss})"
-
-/**
- * polkit_authorization_claim_new:
- * @subject: The subject the claim is for.
- * @action_id: The action identifier for the PolicyKit action the claim is about.
- *
- * Constructs a new #PolkitAuthorizationClaim representing a claim that @subject is authorized for @action_id.
- *
- * Returns: A #PolkitAuthorizationClaim.
- */
-PolkitAuthorizationClaim *
-polkit_authorization_claim_new (PolkitSubject *subject,
- const gchar *action_id)
-{
- GValue *values;
- EggDBusHashTable *attributes;
-
- attributes = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) g_object_unref);
- egg_dbus_hash_table_set_signature (attributes, "s", "s");
-
- values = g_new0 (GValue, 3);
- g_value_init (&(values[0]), POLKIT_TYPE_SUBJECT);
- g_value_set_object (&(values[0]), subject);
- g_value_init (&(values[1]), G_TYPE_STRING);
- g_value_set_string (&(values[1]), action_id);
- g_value_init (&(values[2]), EGG_DBUS_TYPE_HASH_TABLE);
- g_value_take_boxed (&(values[2]), attributes);
-
- return POLKIT_AUTHORIZATION_CLAIM (egg_dbus_structure_new (AUTHORIZATION_CLAIM_SIGNATURE, 3, values));
-}
-
-/**
- * polkit_authorization_claim_get_subject:
- * @authorization_claim: A #PolkitAuthorizationClaim.
- *
- * Gets the subject for @authorization_claim.
- *
- * Returns: A #PolkitSubject instance owned by @authorization_claim. Do not free.
- **/
-PolkitSubject *
-polkit_authorization_claim_get_subject (PolkitAuthorizationClaim *authorization_claim)
-{
- PolkitSubject *subject;
-
- g_return_val_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim), NULL);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (authorization_claim)), AUTHORIZATION_CLAIM_SIGNATURE) == 0, NULL);
-
- egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (authorization_claim),
- 0, &subject,
- -1);
-
- return subject;
-}
-
-/**
- * polkit_authorization_claim_get_action_id:
- * @authorization_claim: A #PolkitAuthorizationClaim.
- *
- * Gets the action identifier for @authorization_claim.
- *
- * Returns: A string owned by @authorization_claim. Do not free.
- **/
-const gchar *
-polkit_authorization_claim_get_action_id (PolkitAuthorizationClaim *authorization_claim)
-{
- const gchar *action_id;
-
- g_return_val_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim), NULL);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (authorization_claim)), AUTHORIZATION_CLAIM_SIGNATURE) == 0, NULL);
-
- egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (authorization_claim),
- 1, &action_id,
- -1);
-
- return action_id;
-}
-
-/**
- * polkit_authorization_claim_get_attributes:
- * @authorization_claim: A #PolkitAuthorizationClaim.
- *
- * Gets the attributes for @authorization_claim.
- *
- * Returns: A #GHashTable owned by @authorization_claim. Do not free or modify.
- **/
-GHashTable *
-polkit_authorization_claim_get_attributes (PolkitAuthorizationClaim *authorization_claim)
-{
- GHashTable *attributes;
-
- g_return_val_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim), NULL);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (authorization_claim)), AUTHORIZATION_CLAIM_SIGNATURE) == 0, NULL);
-
- egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (authorization_claim),
- 2, &attributes,
- -1);
-
- return attributes;
-}
-
-/**
- * polkit_authorization_claim_set_subject:
- * @authorization_claim: A #PolkitAuthorizationClaim.
- * @subject: A #PolkitSubject.
- *
- * Sets the subject of @authorization_claim to @subject.
- **/
-void
-polkit_authorization_claim_set_subject (PolkitAuthorizationClaim *authorization_claim,
- PolkitSubject *subject)
-{
- g_return_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim));
- g_return_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (authorization_claim)), AUTHORIZATION_CLAIM_SIGNATURE) == 0);
-
- egg_dbus_structure_set_element (EGG_DBUS_STRUCTURE (authorization_claim),
- 0, subject,
- -1);
-}
-
-/**
- * polkit_authorization_claim_set_action_id:
- * @authorization_claim: A #PolkitAuthorizationClaim.
- * @action_id: The action identifier for the PolicyKit action the claim is about.
- *
- * Sets the PolicyKit action for @authorization_claim to @action_id.
- **/
-void
-polkit_authorization_claim_set_action_id (PolkitAuthorizationClaim *authorization_claim,
- const gchar *action_id)
-{
- g_return_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim));
- g_return_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (authorization_claim)), AUTHORIZATION_CLAIM_SIGNATURE) == 0);
- g_return_if_fail (action_id != NULL);
-
- egg_dbus_structure_set_element (EGG_DBUS_STRUCTURE (authorization_claim),
- 1, action_id,
- -1);
-}
-
-/**
- * polkit_authorization_claim_set_attribute:
- * @authorization_claim: A #PolkitAuthorizationClaim.
- * @key: Key of the attribute.
- * @value: Value of the attribute or %NULL to clear the attribute for @key.
- *
- * Sets or clear an attribute of @authorization_claim.
- **/
-void
-polkit_authorization_claim_set_attribute (PolkitAuthorizationClaim *authorization_claim,
- const gchar *key,
- const gchar *value)
-{
- EggDBusHashTable *attributes;
-
- g_return_if_fail (POLKIT_IS_AUTHORIZATION_CLAIM (authorization_claim));
- g_return_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (authorization_claim)), AUTHORIZATION_CLAIM_SIGNATURE) == 0);
- g_return_if_fail (key != NULL);
-
- attributes = polkit_authorization_claim_get_attributes (authorization_claim);
-
- if (value == NULL)
- g_hash_table_remove (attributes, key);
- else
- g_hash_table_insert (attributes, g_strdup (key), g_strdup (value));
-}
-
+++ /dev/null
-/*
- * 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
-
-#include <glib-object.h>
-#include <polkit/polkitsubject.h>
-
-#ifndef __POLKIT_AUTHORIZATION_CLAIM_H__
-#define __POLKIT_AUTHORIZATION_CLAIM_H__
-
-G_BEGIN_DECLS
-
-#define POLKIT_TYPE_AUTHORIZATION_CLAIM (polkit_authorization_claim_get_type())
-#define POLKIT_AUTHORIZATION_CLAIM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_AUTHORIZATION_CLAIM, PolkitAuthorizationClaim))
-#define POLKIT_IS_AUTHORIZATION_CLAIM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_AUTHORIZATION_CLAIM))
-#define POLKIT_AUTHORIZATION_CLAIM_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE((o), POLKIT_TYPE_AUTHORIZATION_CLAIM, PolkitAuthorizationClaimIface))
-
-#if 0
-typedef struct _PolkitAuthorizationClaim PolkitAuthorizationClaim; /* Dummy typedef */
-#endif
-typedef struct _PolkitAuthorizationClaimIface PolkitAuthorizationClaimIface;
-
-struct _PolkitAuthorizationClaimIface
-{
- GTypeInterface g_iface;
-};
-
-GType polkit_authorization_claim_get_type (void) G_GNUC_CONST;
-PolkitAuthorizationClaim *polkit_authorization_claim_new (PolkitSubject *subject,
- const gchar *action_id);
-
-void polkit_authorization_claim_set_subject (PolkitAuthorizationClaim *authorization_claim,
- PolkitSubject *subject);
-void polkit_authorization_claim_set_action_id (PolkitAuthorizationClaim *authorization_claim,
- const gchar *action_id);
-void polkit_authorization_claim_set_attribute (PolkitAuthorizationClaim *authorization_claim,
- const gchar *key,
- const gchar *value);
-
-PolkitSubject *polkit_authorization_claim_get_subject (PolkitAuthorizationClaim *authorization_claim);
-const gchar *polkit_authorization_claim_get_action_id (PolkitAuthorizationClaim *authorization_claim);
-GHashTable *polkit_authorization_claim_get_attributes (PolkitAuthorizationClaim *authorization_claim);
-
-
-G_END_DECLS
-
-#endif /* __POLKIT_AUTHORIZATION_CLAIM_H__ */
* Author: David Zeuthen <davidz@redhat.com>
*/
-#include <polkit/polkitbindings.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
-#ifndef __POLKIT_AUTHORITY_STUB_H
-#define __POLKIT_AUTHORITY_STUB_H
+#include "polkiterror.h"
+#include "polkitprivate.h"
-G_BEGIN_DECLS
+GQuark
+polkit_error_quark (void)
+{
+ return _polkit_error_quark ();
+}
-PolkitAuthority *polkit_authority_get (void);
+GType
+polkit_error_get_type (void)
+{
+ return _polkit_error_get_type ();
+}
-G_END_DECLS
-
-#endif /* __POLKIT_AUTHORITY_STUB_H */
--- /dev/null
+/*
+ * 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>
+ */
+
+#ifndef __POLKIT_ERROR_H
+#define __POLKIT_ERROR_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/**
+ * POLKIT_ERROR:
+ *
+ * Error domain for errors when using PolicyKit. Errors in this domain will be from the #PolkitError
+ * enumeration. See #GError for information on error domains
+ */
+#define POLKIT_ERROR polkit_error_quark()
+
+GQuark polkit_error_quark (void);
+
+GType polkit_error_get_type (void) G_GNUC_CONST;
+
+#define POLKIT_TYPE_ERROR (polkit_error_get_type ())
+
+/**
+ * PolkitError:
+ * @POLKIT_ERROR_FAILED: The operation failed
+ * @POLKIT_ERROR_NOT_SUPPORTED: Operation is not supported
+ *
+ * Errors when using PolicyKit.
+ */
+typedef enum
+{
+ POLKIT_ERROR_FAILED = 0,
+ POLKIT_ERROR_NOT_SUPPORTED = 1,
+} PolkitError;
+
+G_END_DECLS
+
+#endif /* __POLKIT_ERROR_H */
+++ /dev/null
-/*
- * 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 "polkitbindings.h"
-#include "polkitsubject.h"
-
-/**
- * SECTION:polkitsubject
- * @title: PolkitSubject
- * @short_description: Subjects
- *
- * The #PolkitSubject type is used for representing subject such as
- * users, groups and processes.
- */
-
-static void
-base_init (gpointer g_iface)
-{
-}
-
-GType
-polkit_subject_get_type (void)
-{
- static GType iface_type = 0;
-
- if (iface_type == 0)
- {
- static const GTypeInfo info =
- {
- sizeof (PolkitSubjectIface),
- base_init, /* base_init */
- NULL, /* base_finalize */
- NULL, /* class_init */
- NULL, /* class_finalize */
- NULL, /* class_data */
- 0, /* instance_size */
- 0, /* n_preallocs */
- NULL, /* instance_init */
- NULL /* value_table */
- };
-
- iface_type = g_type_register_static (G_TYPE_INTERFACE, "PolkitSubject", &info, 0);
-
- g_type_interface_add_prerequisite (iface_type, EGG_DBUS_TYPE_STRUCTURE);
- }
-
- return iface_type;
-}
-
-/**
- * polkit_subject_new_for_unix_process:
- * @unix_process_id: The Process ID.
- *
- * Constructs a new #PolkitSubject for a the UNIX process with PID @process_id.
- *
- * Returns: A #PolkitSubject.
- */
-PolkitSubject *
-polkit_subject_new_for_unix_process (pid_t unix_process_id)
-{
- GValue *values;
- EggDBusHashTable *properties;
-
- properties = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) g_object_unref);
- egg_dbus_hash_table_set_signature (properties, "s", "v");
-
- g_hash_table_insert (properties,
- g_strdup ("unix-process-id"),
- egg_dbus_variant_new_for_uint32 (unix_process_id));
-
- values = g_new0 (GValue, 2);
- g_value_init (&(values[0]), G_TYPE_STRING);
- g_value_set_string (&(values[0]), "unix-process");
- g_value_init (&(values[1]), EGG_DBUS_TYPE_HASH_TABLE);
- g_value_set_boxed (&(values[1]), properties);
-
- return POLKIT_SUBJECT (egg_dbus_structure_new ("(sa{sv})", 2, values));
-}
-
-/**
- * polkit_subject_new_for_unix_user:
- * @unix_user_id: The User ID.
- *
- * Constructs a new #PolkitSubject for a the UNIX user with UID @user_id.
- *
- * Returns: A #PolkitSubject.
- */
-PolkitSubject *
-polkit_subject_new_for_unix_user (uid_t unix_user_id)
-{
- GValue *values;
- EggDBusHashTable *properties;
-
- properties = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) g_object_unref);
- egg_dbus_hash_table_set_signature (properties, "s", "v");
-
- g_hash_table_insert (properties,
- g_strdup ("unix-user-id"),
- egg_dbus_variant_new_for_uint32 (unix_user_id));
-
- values = g_new0 (GValue, 2);
- g_value_init (&(values[0]), G_TYPE_STRING);
- g_value_set_string (&(values[0]), "unix-user");
- g_value_init (&(values[1]), EGG_DBUS_TYPE_HASH_TABLE);
- g_value_set_boxed (&(values[1]), properties);
-
- return POLKIT_SUBJECT (egg_dbus_structure_new ("(sa{sv})", 2, values));
-}
-
-/**
- * polkit_subject_new_for_unix_group:
- * @unix_group_id: The Group ID.
- *
- * Constructs a new #PolkitSubject for a the UNIX group with GID @group_id.
- *
- * Returns: A #PolkitSubject.
- */
-PolkitSubject *
-polkit_subject_new_for_unix_group (gid_t unix_group_id)
-{
- GValue *values;
- EggDBusHashTable *properties;
-
- properties = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- (GDestroyNotify) g_free,
- (GDestroyNotify) g_object_unref);
- egg_dbus_hash_table_set_signature (properties, "s", "v");
-
- g_hash_table_insert (properties,
- g_strdup ("unix-group-id"),
- egg_dbus_variant_new_for_uint32 (unix_group_id));
-
- values = g_new0 (GValue, 2);
- g_value_init (&(values[0]), G_TYPE_STRING);
- g_value_set_string (&(values[0]), "unix-group");
- g_value_init (&(values[1]), EGG_DBUS_TYPE_HASH_TABLE);
- g_value_set_boxed (&(values[1]), properties);
-
- return POLKIT_SUBJECT (egg_dbus_structure_new ("(sa{sv})", 2, values));
-}
-
-/**
- * polkit_subject_get_kind:
- * @subject: A #PolkitSubject.
- *
- * Gets the kind of @subject.
- *
- * Returns: A #PolkitSubjectKind.
- */
-PolkitSubjectKind
-polkit_subject_get_kind (PolkitSubject *subject)
-{
- const gchar *kind_str;
- PolkitSubjectKind kind;
-
- g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), -1);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (subject)), "(sa{sv})") == 0, -1);
-
- egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (subject),
- 0, &kind_str,
- -1);
-
- if (strcmp (kind_str, "unix-process") == 0)
- kind = POLKIT_SUBJECT_KIND_UNIX_PROCESS;
- else if (strcmp (kind_str, "unix-user") == 0)
- kind = POLKIT_SUBJECT_KIND_UNIX_USER;
- else if (strcmp (kind_str, "unix-group") == 0)
- kind = POLKIT_SUBJECT_KIND_UNIX_GROUP;
- else
- {
- g_warning ("unknown kind str '%s'", kind_str);
- kind = -1;
- }
-
- return kind;
-}
-
-/**
- * polkit_subject_equal:
- * @a: A #PolkitSubject.
- * @b: A #PolkitSubject.
- *
- * Checks if the two subjects @a and @b are equal.
- *
- * Returns: %TRUE if @a and @b are equal, %FALSE otherwise.
- **/
-gboolean
-polkit_subject_equal (PolkitSubject *a,
- PolkitSubject *b)
-{
- gboolean ret;
- PolkitSubjectKind kind_a;
- PolkitSubjectKind kind_b;
-
- g_return_val_if_fail (POLKIT_IS_SUBJECT (a), FALSE);
- g_return_val_if_fail (POLKIT_IS_SUBJECT (b), FALSE);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (a)), "(sa{sv})") == 0, FALSE);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (b)), "(sa{sv})") == 0, FALSE);
-
- ret = FALSE;
-
- kind_a = polkit_subject_get_kind (a);
- kind_b = polkit_subject_get_kind (b);
-
- if (kind_a != kind_b)
- goto out;
-
- switch (kind_a)
- {
- case POLKIT_SUBJECT_KIND_UNIX_PROCESS:
- if (polkit_subject_unix_process_get_id (a) == polkit_subject_unix_process_get_id (b))
- ret = TRUE;
- break;
-
- case POLKIT_SUBJECT_KIND_UNIX_USER:
- if (polkit_subject_unix_user_get_id (a) == polkit_subject_unix_user_get_id (b))
- ret = TRUE;
- break;
-
- case POLKIT_SUBJECT_KIND_UNIX_GROUP:
- if (polkit_subject_unix_group_get_id (a) == polkit_subject_unix_group_get_id (b))
- ret = TRUE;
- break;
-
- default:
- /* get_kind() will already have warned */
- goto out;
- }
-
- out:
- return ret;
-}
-
-/**
- * polkit_subject_unix_process_get_id:
- * @subject: A #PolkitSubject of the @POLKIT_SUBJECT_KIND_UNIX_PROCESS kind.
- *
- * Gets the UNIX process id for @subject.
- *
- * Returns: UNIX process id.
- **/
-pid_t
-polkit_subject_unix_process_get_id (PolkitSubject *subject)
-{
- EggDBusHashTable *value;
- EggDBusVariant *variant;
- pid_t pid;
-
- g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), 0);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (subject)), "(sa{sv})") == 0, 0);
- g_return_val_if_fail (polkit_subject_get_kind (subject) != POLKIT_SUBJECT_KIND_UNIX_PROCESS, 0);
-
- egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (subject),
- 1, &value,
- -1);
-
- variant = g_hash_table_lookup (value, "unix-process-id");
- pid = (pid_t) egg_dbus_variant_get_uint32 (variant);
-
- return pid;
-}
-
-/**
- * polkit_subject_unix_user_get_id:
- * @subject: A #PolkitSubject of the @POLKIT_SUBJECT_KIND_UNIX_USER kind.
- *
- * Gets the UNIX user id for @subject.
- *
- * Returns: UNIX user id.
- **/
-uid_t
-polkit_subject_unix_user_get_id (PolkitSubject *subject)
-{
- EggDBusHashTable *value;
- EggDBusVariant *variant;
- uid_t uid;
-
- g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), 0);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (subject)), "(sa{sv})") == 0, 0);
- g_return_val_if_fail (polkit_subject_get_kind (subject) != POLKIT_SUBJECT_KIND_UNIX_USER, 0);
-
- egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (subject),
- 1, &value,
- -1);
-
- variant = g_hash_table_lookup (value, "unix-user-id");
- uid = (uid_t) egg_dbus_variant_get_uint32 (variant);
-
- return uid;
-}
-
-/**
- * polkit_subject_unix_group_get_id:
- * @subject: A #PolkitSubject of the @POLKIT_SUBJECT_KIND_UNIX_GROUP kind.
- *
- * Gets the UNIX group id for @subject.
- *
- * Returns: UNIX group id.
- **/
-gid_t
-polkit_subject_unix_group_get_id (PolkitSubject *subject)
-{
- EggDBusHashTable *value;
- EggDBusVariant *variant;
- gid_t gid;
-
- g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), 0);
- g_return_val_if_fail (strcmp (egg_dbus_structure_get_signature (EGG_DBUS_STRUCTURE (subject)), "(sa{sv})") == 0, 0);
- g_return_val_if_fail (polkit_subject_get_kind (subject) != POLKIT_SUBJECT_KIND_UNIX_GROUP, 0);
-
- egg_dbus_structure_get_element (EGG_DBUS_STRUCTURE (subject),
- 1, &value,
- -1);
-
- variant = g_hash_table_lookup (value, "unix-group-id");
- gid = (gid_t) egg_dbus_variant_get_uint32 (variant);
-
- return gid;
-}
-
+++ /dev/null
-/*
- * 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>
- */
-
-#ifndef __POLKIT_SUBJECT_H
-#define __POLKIT_SUBJECT_H
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <glib-object.h>
-#include <polkit/polkitbindings.h>
-
-G_BEGIN_DECLS
-
-#define POLKIT_TYPE_SUBJECT (polkit_subject_get_type())
-#define POLKIT_SUBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_SUBJECT, PolkitSubject))
-#define POLKIT_IS_SUBJECT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_SUBJECT))
-#define POLKIT_SUBJECT_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE((o), POLKIT_TYPE_SUBJECT, PolkitSubjectIface))
-
-#if 0
-typedef struct _PolkitSubject PolkitSubject; /* Dummy typedef */
-#endif
-typedef struct _PolkitSubjectIface PolkitSubjectIface;
-
-typedef enum
-{
- POLKIT_SUBJECT_KIND_UNIX_PROCESS,
- POLKIT_SUBJECT_KIND_UNIX_USER,
- POLKIT_SUBJECT_KIND_UNIX_GROUP,
-} PolkitSubjectKind;
-
-struct _PolkitSubjectIface
-{
- GTypeInterface g_iface;
-};
-
-GType polkit_subject_get_type (void) G_GNUC_CONST;
-PolkitSubject *polkit_subject_new_for_unix_process (pid_t unix_process_id);
-PolkitSubject *polkit_subject_new_for_unix_user (uid_t unix_user_id);
-PolkitSubject *polkit_subject_new_for_unix_group (gid_t unix_group_id);
-PolkitSubjectKind polkit_subject_get_kind (PolkitSubject *subject);
-pid_t polkit_subject_unix_process_get_id (PolkitSubject *subject);
-uid_t polkit_subject_unix_user_get_id (PolkitSubject *subject);
-gid_t polkit_subject_unix_group_get_id (PolkitSubject *subject);
-gboolean polkit_subject_equal (PolkitSubject *a,
- PolkitSubject *b);
-
-G_END_DECLS
-
-#endif /* __POLKIT_SUBJECT_H */
-DPACKAGE_LIB_DIR=\""$(libdir)"\" \
-D_POSIX_PTHREAD_SEMANTICS \
-D_REENTRANT \
+ -DEGG_DBUS_I_KNOW_API_IS_SUBJECT_TO_CHANGE \
$(NULL)
lib_LTLIBRARIES=libpolkit-backend-1.la
libpolkit_backend_1include_HEADERS = \
polkitbackend.h \
+ polkitbackendtypes.h \
+ polkitbackendauthority.h \
polkitbackendlocalauthority.h \
polkitbackendactionpool.h \
+ polkitbackendserver.h \
$(NULL)
libpolkit_backend_1_la_SOURCES = \
polkitbackend.h \
+ polkitbackendtypes.h \
+ polkitbackendauthority.h polkitbackendauthority.c \
polkitbackendlocalauthority.h polkitbackendlocalauthority.c \
polkitbackendactionpool.h polkitbackendactionpool.c \
+ polkitbackendserver.h polkitbackendserver.c \
$(NULL)
libpolkit_backend_1_la_CFLAGS = \
#define __POLKIT_BACKEND_H
#define _POLKIT_BACKEND_INSIDE_POLKIT_BACKEND_H 1
+#include <polkitbackend/polkitbackendtypes.h>
+#include <polkitbackend/polkitbackendauthority.h>
#include <polkitbackend/polkitbackendlocalauthority.h>
#include <polkitbackend/polkitbackendactionpool.h>
+#include <polkitbackend/polkitbackendserver.h>
#undef _POLKIT_BACKEND_INSIDE_POLKIT_BACKEND_H
#endif /* __POLKIT_BACKEND_H */
#include <pwd.h>
#include <string.h>
#include <expat.h>
+
#include <polkit/polkit.h>
+#include <polkit/polkitprivate.h>
+
#include "polkitbackendactionpool.h"
typedef struct
GHashTable *localized_message;
/* this maps from annotation key (string) to annotation value (also a string) */
- GHashTable *annotations;
+ EggDBusHashMap *annotations;
} ParsedAction;
static void
g_hash_table_unref (action->localized_description);
g_hash_table_unref (action->localized_message);
- g_hash_table_unref (action->annotations);
+ g_object_unref (action->annotations);
g_free (action);
}
{
PolkitBackendActionPoolPrivate *priv;
PolkitActionDescription *ret;
+ _PolkitActionDescription *real;
ParsedAction *parsed_action;
gchar *description;
gchar *message;
- GValue *values;
g_return_val_if_fail (POLKIT_BACKEND_IS_ACTION_POOL (pool), NULL);
parsed_action->message,
locale));
- values = g_new0 (GValue, 7);
- g_value_init (&(values[0]), G_TYPE_STRING);
- g_value_set_string (&(values[0]), parsed_action->action_id);
- g_value_init (&(values[1]), G_TYPE_STRING);
- g_value_set_string (&(values[1]), description != NULL ? description : g_strdup (""));
- g_value_init (&(values[2]), G_TYPE_STRING);
- g_value_set_string (&(values[2]), message != NULL ? message : g_strdup (""));
- g_value_init (&(values[3]), G_TYPE_STRING);
- g_value_set_string (&(values[3]), parsed_action->vendor_name != NULL ? parsed_action->vendor_name : g_strdup (""));
- g_value_init (&(values[4]), G_TYPE_STRING);
- g_value_set_string (&(values[4]), parsed_action->vendor_url != NULL ? parsed_action->vendor_url : g_strdup (""));
- g_value_init (&(values[5]), G_TYPE_STRING);
- g_value_set_string (&(values[5]), parsed_action->icon_name != NULL ? parsed_action->icon_name : g_strdup (""));
- g_value_init (&(values[6]), G_TYPE_HASH_TABLE);
- g_value_set_boxed (&(values[6]), parsed_action->annotations);
-
- ret = POLKIT_ACTION_DESCRIPTION (egg_dbus_structure_new ("(ssssssa{ss})", 7, values));
+ real = _polkit_action_description_new (action_id,
+ description,
+ message,
+ parsed_action->vendor_name,
+ parsed_action->vendor_url,
+ parsed_action->icon_name,
+ parsed_action->annotations);
+
+ ret = polkit_action_description_new_for_real (real);
+ g_object_unref (real);
out:
return ret;
char *elem_lang;
char *annotate_key;
- GHashTable *annotations;
+ EggDBusHashMap *annotations;
PolkitBackendActionPool *pool;
} ParserData;
pd->policy_description_nolang = NULL;
g_free (pd->policy_message_nolang);
pd->policy_message_nolang = NULL;
- if (pd->policy_descriptions != NULL) {
- g_hash_table_unref (pd->policy_descriptions);
- pd->policy_descriptions = NULL;
- }
- if (pd->policy_messages != NULL) {
- g_hash_table_unref (pd->policy_messages);
- pd->policy_messages = NULL;
- }
+ if (pd->policy_descriptions != NULL)
+ {
+ g_hash_table_unref (pd->policy_descriptions);
+ pd->policy_descriptions = NULL;
+ }
+ if (pd->policy_messages != NULL)
+ {
+ g_hash_table_unref (pd->policy_messages);
+ pd->policy_messages = NULL;
+ }
g_free (pd->annotate_key);
pd->annotate_key = NULL;
- if (pd->annotations != NULL) {
- g_hash_table_unref (pd->annotations);
- pd->annotations = NULL;
- }
+ if (pd->annotations != NULL)
+ {
+ g_object_unref (pd->annotations);
+ pd->annotations = NULL;
+ }
g_free (pd->elem_lang);
pd->elem_lang = NULL;
}
g_str_equal,
g_free,
g_free);
- pd->annotations = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- g_free,
- g_free);
+ pd->annotations = egg_dbus_hash_map_new (G_TYPE_STRING, g_free, G_TYPE_STRING, g_free);
/* initialize defaults */
//pd->defaults_allow_any = POLKIT_RESULT_NO;
//pd->defaults_allow_inactive = POLKIT_RESULT_NO;
break;
case STATE_IN_ANNOTATE:
- g_hash_table_insert (pd->annotations,
- g_strdup (pd->annotate_key),
- str);
+ egg_dbus_hash_map_insert (pd->annotations,
+ g_strdup (pd->annotate_key),
+ str);
str = NULL;
break;
--- /dev/null
+/*
+ * 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>
+ */
+
+#include "config.h"
+#include <errno.h>
+#include <pwd.h>
+#include <string.h>
+#include <polkit/polkit.h>
+#include "polkitbackendauthority.h"
+
+G_DEFINE_ABSTRACT_TYPE (PolkitBackendAuthority, polkit_backend_authority, G_TYPE_OBJECT);
+
+static void
+polkit_backend_authority_init (PolkitBackendAuthority *local_authority)
+{
+}
+
+static void
+polkit_backend_authority_class_init (PolkitBackendAuthorityClass *klass)
+{
+}
+
+GList *
+polkit_backend_authority_enumerate_actions (PolkitBackendAuthority *authority,
+ const gchar *locale)
+{
+ PolkitBackendAuthorityClass *klass;
+
+ klass = POLKIT_BACKEND_AUTHORITY_GET_CLASS (authority);
+
+ return klass->enumerate_actions (authority, locale);
+}
+
--- /dev/null
+/*
+ * 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_BACKEND_COMPILATION) && !defined(_POLKIT_BACKEND_INSIDE_POLKIT_BACKEND_H)
+#error "Only <polkitbackend/polkitbackend.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef __POLKIT_BACKEND_AUTHORITY_H
+#define __POLKIT_BACKEND_AUTHORITY_H
+
+#include <glib-object.h>
+#include "polkitbackendtypes.h"
+
+G_BEGIN_DECLS
+
+#define POLKIT_BACKEND_TYPE_AUTHORITY (polkit_backend_authority_get_type ())
+#define POLKIT_BACKEND_AUTHORITY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_BACKEND_TYPE_AUTHORITY, PolkitBackendAuthority))
+#define POLKIT_BACKEND_AUTHORITY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), POLKIT_BACKEND_TYPE_AUTHORITY, PolkitBackendAuthorityClass))
+#define POLKIT_BACKEND_AUTHORITY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_BACKEND_TYPE_AUTHORITY,PolkitBackendAuthorityClass))
+#define POLKIT_BACKEND_IS_AUTHORITY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_BACKEND_TYPE_AUTHORITY))
+#define POLKIT_BACKEND_IS_AUTHORITY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_BACKEND_TYPE_AUTHORITY))
+
+typedef struct _PolkitBackendAuthorityClass PolkitBackendAuthorityClass;
+
+struct _PolkitBackendAuthority
+{
+ GObject parent_instance;
+};
+
+struct _PolkitBackendAuthorityClass
+{
+ GObjectClass parent_class;
+
+ /*< public >*/
+
+ GList * (*enumerate_actions) (PolkitBackendAuthority *authority,
+ const gchar *locale);
+
+ /*< private >*/
+ /* Padding for future expansion */
+ void (*_polkit_reserved1) (void);
+ void (*_polkit_reserved2) (void);
+ void (*_polkit_reserved3) (void);
+ void (*_polkit_reserved4) (void);
+ void (*_polkit_reserved5) (void);
+ void (*_polkit_reserved6) (void);
+ void (*_polkit_reserved7) (void);
+ void (*_polkit_reserved8) (void);
+};
+
+GType polkit_backend_authority_get_type (void) G_GNUC_CONST;
+
+GList *polkit_backend_authority_enumerate_actions (PolkitBackendAuthority *authority,
+ const gchar *locale);
+
+G_END_DECLS
+
+#endif /* __POLKIT_BACKEND_AUTHORITY_H */
+
} PolkitBackendLocalAuthorityPrivate;
-static void authority_iface_init (PolkitAuthorityIface *authority_iface,
- gpointer iface_data);
+static GList *polkit_backend_local_authority_enumerate_actions (PolkitBackendAuthority *authority,
+ const gchar *locale);
-G_DEFINE_TYPE_WITH_CODE (PolkitBackendLocalAuthority, polkit_backend_local_authority, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (POLKIT_TYPE_AUTHORITY,
- authority_iface_init)
- );
-#define POLKIT_BACKEND_LOCAL_AUTHORITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), POLKIT_BACKEND_TYPE_LOCAL_AUTHORITY, PolkitBackendLocalAuthorityPrivate))
+G_DEFINE_TYPE (PolkitBackendLocalAuthority, polkit_backend_local_authority, POLKIT_BACKEND_TYPE_AUTHORITY);
+#define POLKIT_BACKEND_LOCAL_AUTHORITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), POLKIT_BACKEND_TYPE_LOCAL_AUTHORITY, PolkitBackendLocalAuthorityPrivate))
static void
polkit_backend_local_authority_init (PolkitBackendLocalAuthority *local_authority)
static void
polkit_backend_local_authority_class_init (PolkitBackendLocalAuthorityClass *klass)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GObjectClass *gobject_class;
+ PolkitBackendAuthorityClass *authority_class;
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ authority_class = POLKIT_BACKEND_AUTHORITY_CLASS (klass);
gobject_class->finalize = polkit_backend_local_authority_finalize;
+ authority_class->enumerate_actions = polkit_backend_local_authority_enumerate_actions;
+
g_type_class_add_private (klass, sizeof (PolkitBackendLocalAuthorityPrivate));
}
-PolkitBackendLocalAuthority *
+PolkitBackendAuthority *
polkit_backend_local_authority_new (void)
{
+ return POLKIT_BACKEND_AUTHORITY (g_object_new (POLKIT_BACKEND_TYPE_LOCAL_AUTHORITY,
+ NULL));
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static GList *
+polkit_backend_local_authority_enumerate_actions (PolkitBackendAuthority *authority,
+ const gchar *locale)
+{
PolkitBackendLocalAuthority *local_authority;
+ PolkitBackendLocalAuthorityPrivate *priv;
- local_authority = POLKIT_BACKEND_LOCAL_AUTHORITY (g_object_new (POLKIT_BACKEND_TYPE_LOCAL_AUTHORITY,
- NULL));
+ local_authority = POLKIT_BACKEND_LOCAL_AUTHORITY (authority);
+ priv = POLKIT_BACKEND_LOCAL_AUTHORITY_GET_PRIVATE (local_authority);
- return local_authority;
+ return polkit_backend_action_pool_get_all_actions (priv->action_pool, locale);
}
+#if 0
/* ---------------------------------------------------------------------------------------------------- */
static void
}
/* ---------------------------------------------------------------------------------------------------- */
+#endif
#error "Only <polkitbackend/polkitbackend.h> can be included directly, this file may disappear or change contents."
#endif
-#include <glib-object.h>
-
#ifndef __POLKIT_BACKEND_LOCAL_AUTHORITY_H
#define __POLKIT_BACKEND_LOCAL_AUTHORITY_H
+#include <glib-object.h>
+#include <polkitbackend/polkitbackendauthority.h>
+
G_BEGIN_DECLS
#define POLKIT_BACKEND_TYPE_LOCAL_AUTHORITY (polkit_backend_local_authority_get_type ())
struct _PolkitBackendLocalAuthority
{
- GObject parent_instance;
+ PolkitBackendAuthority parent_instance;
};
struct _PolkitBackendLocalAuthorityClass
{
- GObjectClass parent_class;
+ PolkitBackendAuthorityClass parent_class;
/*< public >*/
void (*_polkit_reserved8) (void);
};
-GType polkit_backend_local_authority_get_type (void) G_GNUC_CONST;
-
-PolkitBackendLocalAuthority *polkit_backend_local_authority_new (void);
+GType polkit_backend_local_authority_get_type (void) G_GNUC_CONST;
+PolkitBackendAuthority *polkit_backend_local_authority_new (void);
G_END_DECLS
--- /dev/null
+/*
+ * 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>
+ */
+
+#include "config.h"
+#include <errno.h>
+#include <pwd.h>
+#include <string.h>
+#include <polkit/polkit.h>
+#include <polkit/polkitprivate.h>
+
+#include "polkitbackendauthority.h"
+#include "polkitbackendserver.h"
+
+struct _PolkitBackendServer
+{
+ GObject parent_instance;
+
+ PolkitBackendAuthority *authority;
+};
+
+struct _PolkitBackendServerClass
+{
+ GObjectClass parent_class;
+};
+
+static void authority_iface_init (_PolkitAuthorityIface *authority_iface);
+
+G_DEFINE_TYPE_WITH_CODE (PolkitBackendServer, polkit_backend_server, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (_POLKIT_TYPE_AUTHORITY, authority_iface_init)
+ );
+
+static void
+polkit_backend_server_init (PolkitBackendServer *local_server)
+{
+}
+
+static void
+polkit_backend_server_finalize (GObject *object)
+{
+ PolkitBackendServer *server;
+
+ server = POLKIT_BACKEND_SERVER (object);
+
+ g_object_unref (server->authority);
+}
+
+static void
+polkit_backend_server_class_init (PolkitBackendServerClass *klass)
+{
+ GObjectClass *gobject_class;
+
+ gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->finalize = polkit_backend_server_finalize;
+}
+
+PolkitBackendServer *
+polkit_backend_server_new (PolkitBackendAuthority *authority)
+{
+ PolkitBackendServer *server;
+
+ server = POLKIT_BACKEND_SERVER (g_object_new (POLKIT_BACKEND_TYPE_SERVER, NULL));
+
+ server->authority = g_object_ref (authority);
+
+ return server;
+}
+
+static void
+authority_handle_enumerate_actions (_PolkitAuthority *instance,
+ const gchar *locale,
+ EggDBusMethodInvocation *method_invocation)
+{
+ PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance);
+ EggDBusArraySeq *array;
+ GList *actions;
+ GList *l;
+
+ actions = polkit_backend_authority_enumerate_actions (server->authority, locale);
+
+ array = egg_dbus_array_seq_new (_POLKIT_TYPE_ACTION_DESCRIPTION, NULL, NULL, NULL);
+
+ for (l = actions; l != NULL; l = l->next)
+ {
+ PolkitActionDescription *ad = POLKIT_ACTION_DESCRIPTION (l->data);
+ egg_dbus_array_seq_add (array, polkit_action_description_get_real (ad));
+ }
+
+ _polkit_authority_handle_enumerate_actions_finish (method_invocation, array);
+
+ g_object_unref (array);
+
+ g_list_foreach (actions, (GFunc) g_object_unref, NULL);
+ g_list_free (actions);
+}
+
+static void
+authority_iface_init (_PolkitAuthorityIface *authority_iface)
+{
+ authority_iface->handle_enumerate_actions = authority_handle_enumerate_actions;
+}
--- /dev/null
+/*
+ * 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_BACKEND_COMPILATION) && !defined(_POLKIT_BACKEND_INSIDE_POLKIT_BACKEND_H)
+#error "Only <polkitbackend/polkitbackend.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef __POLKIT_BACKEND_SERVER_H
+#define __POLKIT_BACKEND_SERVER_H
+
+#include <glib-object.h>
+#include "polkitbackendtypes.h"
+
+G_BEGIN_DECLS
+
+#define POLKIT_BACKEND_TYPE_SERVER (polkit_backend_server_get_type ())
+#define POLKIT_BACKEND_SERVER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_BACKEND_TYPE_SERVER, PolkitBackendServer))
+#define POLKIT_BACKEND_SERVER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), POLKIT_BACKEND_TYPE_SERVER, PolkitBackendServerClass))
+#define POLKIT_BACKEND_SERVER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_BACKEND_TYPE_SERVER,PolkitBackendServerClass))
+#define POLKIT_BACKEND_IS_SERVER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_BACKEND_TYPE_SERVER))
+#define POLKIT_BACKEND_IS_SERVER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_BACKEND_TYPE_SERVER))
+
+typedef struct _PolkitBackendServerClass PolkitBackendServerClass;
+
+GType polkit_backend_server_get_type (void) G_GNUC_CONST;
+
+PolkitBackendServer *polkit_backend_server_new (PolkitBackendAuthority *authority);
+
+G_END_DECLS
+
+#endif /* __POLKIT_BACKEND_SERVER_H */
+
--- /dev/null
+/*
+ * 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>
+ */
+
+#ifndef __POLKIT_BACKEND_TYPES_H
+#define __POLKIT_BACKEND_TYPES_H
+
+#include <glib-object.h>
+
+struct _PolkitBackendAuthority;
+typedef struct _PolkitBackendAuthority PolkitBackendAuthority;
+
+struct _PolkitBackendServer;
+typedef struct _PolkitBackendServer PolkitBackendServer;
+
+#endif /* __POLKIT_BACKEND_TYPES_H */
+
-DPACKAGE_LIB_DIR=\""$(libdir)"\" \
-D_POSIX_PTHREAD_SEMANTICS \
-D_REENTRANT \
+ -DEGG_DBUS_I_KNOW_API_IS_SUBJECT_TO_CHANGE \
$(NULL)
libexec_PROGRAMS = polkitd-1
#endif
#include <polkit/polkit.h>
+#include <polkit/polkitprivate.h>
+
#include <polkitbackend/polkitbackend.h>
-static PolkitAuthority *
+static _PolkitAuthority *
get_authority_backend (void)
{
+ PolkitBackendAuthority *authority;
+ PolkitBackendServer *server;
+
/* TODO: use extension points etc. */
- return POLKIT_AUTHORITY (polkit_backend_local_authority_new ());
+ authority = polkit_backend_local_authority_new ();
+
+ server = polkit_backend_server_new (authority);
+
+ g_object_unref (authority);
+
+ return _POLKIT_AUTHORITY (server);
}
int
GError *error;
GMainLoop *loop;
EggDBusConnection *connection;
- PolkitAuthority *authority;
+ _PolkitAuthority *authority;
ret = 1;
+ authority = NULL;
+ connection = NULL;
g_type_init ();
- polkit_bindings_register_types (); /* TODO: use __attribute ((constructor)) */
loop = g_main_loop_new (NULL, FALSE);
connection = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM);
error = NULL;
- if (!egg_dbus_bus_invoke_request_name_sync (egg_dbus_connection_get_bus_proxy (connection),
- 0, /* call flags */
- "org.freedesktop.PolicyKit1",
- 0, /* flags */
- &rn_ret,
- NULL,
- &error))
+ if (!egg_dbus_bus_request_name_sync (egg_dbus_connection_get_bus (connection),
+ EGG_DBUS_CALL_FLAGS_NONE,
+ "org.freedesktop.PolicyKit1",
+ EGG_DBUS_REQUEST_NAME_FLAGS_NONE,
+ &rn_ret,
+ NULL,
+ &error))
{
g_warning ("error: %s", error->message);
g_error_free (error);
authority = get_authority_backend ();
- egg_dbus_connection_export_object (connection,
- G_OBJECT (authority),
- "/org/freedesktop/PolicyKit1/Authority");
+ egg_dbus_connection_register_interface (connection,
+ "/org/freedesktop/PolicyKit1/Authority",
+ _POLKIT_TYPE_AUTHORITY,
+ G_OBJECT (authority),
+ G_TYPE_INVALID);
g_main_loop_run (loop);
- g_object_unref (authority);
- g_object_unref (connection);
ret = 0;
out:
+ if (authority != NULL)
+ g_object_unref (authority);
+ if (connection != NULL)
+ g_object_unref (connection);
return ret;
}
#include <polkit/polkit.h>
-int
-main (int argc, char *argv[])
+static PolkitAuthority *authority;
+
+static void
+list_actions (void)
{
GError *error;
- PolkitAuthority *authority;
- gchar *result;
+ GList *actions;
+ GList *l;
+
+ error = NULL;
+ actions = polkit_authority_enumerate_actions_sync (authority,
+ "",
+ NULL,
+ &error);
+ if (error != NULL)
+ {
+ g_printerr ("Error enumerating actions: %s\n", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ for (l = actions; l != NULL; l = l->next)
+ {
+ PolkitActionDescription *action = POLKIT_ACTION_DESCRIPTION (l->data);
+
+ g_print ("%s\n", polkit_action_description_get_action_id (action));
+ }
+ g_list_foreach (actions, (GFunc) g_object_unref, NULL);
+ g_list_free (actions);
+
+ out:
+ ;
+}
+
+int
+main (int argc, char *argv[])
+{
g_type_init ();
authority = polkit_authority_get ();
- error = NULL;
- polkit_authority_invoke_say_hello_sync (authority,
- 0, /* call_flags */
- "Hi there!",
- &result,
- NULL,
- &error);
- g_print ("Authority replied: %s\n", result);
- g_free (result);
+ list_actions ();
g_object_unref (authority);