Commit 26454597 authored by David Zeuthen's avatar David Zeuthen

update to latest EggDBus and rework how things are done

parent fce5a409
......@@ -2,41 +2,63 @@
"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>
......
......@@ -12,21 +12,24 @@ INCLUDES = \
-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)
......@@ -35,27 +38,19 @@ lib_LTLIBRARIES=libpolkit-gobject-1.la
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 = \
......
......@@ -23,17 +23,11 @@
#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 */
......@@ -22,232 +22,120 @@
#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;
}
......@@ -22,27 +22,23 @@
#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);
......@@ -51,7 +47,6 @@ const gchar *polkit_action_description_get_message (PolkitActionDescriptio
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
......
/*
* 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;