Commit 7ef7e0a3 authored by David Zeuthen's avatar David Zeuthen

add a ActionPool class and rename BackendLocal to BackendLocalAuthority

parent d5a8a9bd
......@@ -72,6 +72,7 @@
<chapter id="extending">
<title>Extending PolicyKit</title>
<xi:include href="../polkitbackend/xml/polkitbackendlocal.xml"/>
<xi:include href="../polkitbackend/xml/polkitbackendactionpool.xml"/>
</chapter>
</reference>
......
......@@ -20,12 +20,14 @@ libpolkit_backend_1includedir=$(includedir)/polkit-1/polkitbackend
libpolkit_backend_1include_HEADERS = \
polkitbackend.h \
polkitbackendlocal.h \
polkitbackendlocalauthority.h \
polkitbackendactionpool.h \
$(NULL)
libpolkit_backend_1_la_SOURCES = \
polkitbackend.h \
polkitbackendlocal.h polkitbackendlocal.c \
polkitbackendlocalauthority.h polkitbackendlocalauthority.c \
polkitbackendactionpool.h polkitbackendactionpool.c \
$(NULL)
libpolkit_backend_1_la_CFLAGS = \
......
......@@ -23,7 +23,8 @@
#define __POLKIT_BACKEND_H
#define _POLKIT_BACKEND_INSIDE_POLKIT_BACKEND_H 1
#include <polkitbackend/polkitbackendlocal.h>
#include <polkitbackend/polkitbackendlocalauthority.h>
#include <polkitbackend/polkitbackendactionpool.h>
#undef _POLKIT_BACKEND_INSIDE_POLKIT_BACKEND_H
#endif /* __POLKIT_BACKEND_H */
......
/*
* 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 "polkitbackendactionpool.h"
/* TODO: locking */
typedef struct
{
GFile *directory;
} PolkitBackendActionPoolPrivate;
enum
{
PROP_0,
PROP_DIRECTORY,
};
#define POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), POLKIT_TYPE_BACKEND_ACTION_POOL, PolkitBackendActionPoolPrivate))
G_DEFINE_TYPE (PolkitBackendActionPool, polkit_backend_action_pool, G_TYPE_OBJECT);
static void
polkit_backend_action_pool_init (PolkitBackendActionPool *pool)
{
PolkitBackendActionPoolPrivate *priv;
priv = POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE (pool);
}
static void
polkit_backend_action_pool_finalize (GObject *object)
{
PolkitBackendActionPool *pool;
PolkitBackendActionPoolPrivate *priv;
pool = POLKIT_BACKEND_ACTION_POOL (object);
priv = POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE (pool);
if (priv->directory != NULL)
g_object_unref (priv->directory);
G_OBJECT_CLASS (polkit_backend_action_pool_parent_class)->finalize (object);
}
static void
polkit_backend_action_pool_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
PolkitBackendActionPool *pool;
PolkitBackendActionPoolPrivate *priv;
pool = POLKIT_BACKEND_ACTION_POOL (object);
priv = POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE (pool);
switch (prop_id)
{
case PROP_DIRECTORY:
g_value_set_object (value, priv->directory);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
polkit_backend_action_pool_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
PolkitBackendActionPool *pool;
PolkitBackendActionPoolPrivate *priv;
pool = POLKIT_BACKEND_ACTION_POOL (object);
priv = POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE (pool);
switch (prop_id)
{
case PROP_DIRECTORY:
priv->directory = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
polkit_backend_action_pool_class_init (PolkitBackendActionPoolClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->get_property = polkit_backend_action_pool_get_property;
gobject_class->set_property = polkit_backend_action_pool_set_property;
gobject_class->finalize = polkit_backend_action_pool_finalize;
g_type_class_add_private (klass, sizeof (PolkitBackendActionPoolPrivate));
/**
* PolkitBackendActionPool:directory:
*
* The directory to load action description files from.
*/
g_object_class_install_property (gobject_class,
PROP_DIRECTORY,
g_param_spec_object ("directory",
"Directory",
"Directory to load action description files from",
G_TYPE_FILE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
}
/**
* polkit_backend_action_pool_new:
* @directory: A #GFile for the directory holding PolicyKit action description files.
*
* Creates a new #PolkitBackendPool that can be used for looking up #PolkitActionDescription objects.
*
* Returns: A #PolkitBackendActionPool. Free with g_object_unref().
**/
PolkitBackendActionPool *
polkit_backend_action_pool_new (GFile *directory)
{
PolkitBackendActionPool *pool;
pool = POLKIT_BACKEND_ACTION_POOL (g_object_new (POLKIT_TYPE_BACKEND_ACTION_POOL,
"directory", directory,
NULL));
return pool;
}
/* ---------------------------------------------------------------------------------------------------- */
/**
* polkit_backend_action_pool_get_localized_actions:
* @pool: A #PolkitBackendActionPool.
* @locale: The locale to get descriptions for or %NULL for system locale.
*
* Gets all registered PolicyKit action descriptions from @pool with strings for @locale.
*
* Returns: A #GList of #PolkitActionDescription objects. This list
* should be freed with g_list_free() after each element have
* been unreffed with g_object_unref().
**/
GList *
polkit_backend_action_pool_get_localized_actions (PolkitBackendActionPool *pool,
const gchar *locale)
{
GList *ret;
PolkitBackendActionPoolPrivate *priv;
g_return_val_if_fail (POLKIT_BACKEND_IS_ACTION_POOL (pool), NULL);
priv = POLKIT_BACKEND_ACTION_POOL_GET_PRIVATE (pool);
ret = NULL;
return ret;
}
/* ---------------------------------------------------------------------------------------------------- */
/*
* 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
#include <glib-object.h>
#ifndef __POLKIT_BACKEND_ACTION_POOL_H
#define __POLKIT_BACKEND_ACTION_POOL_H
G_BEGIN_DECLS
#define POLKIT_TYPE_BACKEND_ACTION_POOL (polkit_backend_action_pool_get_type ())
#define POLKIT_BACKEND_ACTION_POOL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_BACKEND_ACTION_POOL, PolkitBackendActionPool))
#define POLKIT_BACKEND_ACTION_POOL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), POLKIT_TYPE_BACKEND_ACTION_POOL, PolkitBackendActionPoolClass))
#define POLKIT_BACKEND_ACTION_POOL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_BACKEND_ACTION_POOL,PolkitBackendActionPoolClass))
#define POLKIT_BACKEND_IS_ACTION_POOL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_BACKEND_ACTION_POOL))
#define POLKIT_BACKEND_IS_ACTION_POOL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_BACKEND_ACTION_POOL))
typedef struct _PolkitBackendActionPool PolkitBackendActionPool;
typedef struct _PolkitBackendActionPoolClass PolkitBackendActionPoolClass;
struct _PolkitBackendActionPool
{
GObject parent_instance;
};
struct _PolkitBackendActionPoolClass
{
GObjectClass parent_class;
/*< public >*/
/*< 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_action_pool_get_type (void) G_GNUC_CONST;
PolkitBackendActionPool *polkit_backend_action_pool_new (GFile *directory);
GList *polkit_backend_action_pool_get_localized_actions (PolkitBackendActionPool *pool,
const gchar *locale);
G_END_DECLS
#endif /* __POLKIT_BACKEND_ACTION_POOL_H */
......@@ -24,69 +24,79 @@
#include <pwd.h>
#include <string.h>
#include <polkit/polkit.h>
#include "polkitbackendlocal.h"
/* TODO: locking */
#include "polkitbackendlocalauthority.h"
#include "polkitbackendactionpool.h"
typedef struct
{
guint foo;
} PolkitBackendLocalPrivate;
PolkitBackendActionPool *action_pool;
} PolkitBackendLocalAuthorityPrivate;
static void authority_iface_init (PolkitAuthorityIface *authority_iface,
gpointer iface_data);
G_DEFINE_TYPE_WITH_CODE (PolkitBackendLocal, polkit_backend_local, G_TYPE_OBJECT,
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_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), POLKIT_TYPE_BACKEND_LOCAL, PolkitBackendLocalPrivate))
#define POLKIT_BACKEND_LOCAL_AUTHORITY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), POLKIT_TYPE_BACKEND_LOCAL_AUTHORITY, PolkitBackendLocalAuthorityPrivate))
static void
polkit_backend_local_finalize (GObject *object)
polkit_backend_local_authority_init (PolkitBackendLocalAuthority *local_authority)
{
PolkitBackendLocal *backend;
PolkitBackendLocalPrivate *priv;
PolkitBackendLocalAuthorityPrivate *priv;
GFile *action_desc_directory;
backend = POLKIT_BACKEND_LOCAL (object);
priv = POLKIT_BACKEND_LOCAL_GET_PRIVATE (backend);
priv = POLKIT_BACKEND_LOCAL_AUTHORITY_GET_PRIVATE (local_authority);
G_OBJECT_CLASS (polkit_backend_local_parent_class)->finalize (object);
action_desc_directory = g_file_new_for_path (PACKAGE_DATA_DIR "/polkit-1/actions");
priv->action_pool = polkit_backend_action_pool_new (action_desc_directory);
g_object_unref (action_desc_directory);
}
static void
polkit_backend_local_class_init (PolkitBackendLocalClass *klass)
polkit_backend_local_authority_finalize (GObject *object)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
PolkitBackendLocalAuthority *local_authority;
PolkitBackendLocalAuthorityPrivate *priv;
gobject_class->finalize = polkit_backend_local_finalize;
local_authority = POLKIT_BACKEND_LOCAL_AUTHORITY (object);
priv = POLKIT_BACKEND_LOCAL_AUTHORITY_GET_PRIVATE (local_authority);
g_type_class_add_private (klass, sizeof (PolkitBackendLocalPrivate));
}
if (priv->action_pool != NULL)
g_object_unref (priv->action_pool);
G_OBJECT_CLASS (polkit_backend_local_authority_parent_class)->finalize (object);
}
static void
polkit_backend_local_init (PolkitBackendLocal *backend)
polkit_backend_local_authority_class_init (PolkitBackendLocalAuthorityClass *klass)
{
PolkitBackendLocalPrivate *priv;
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = polkit_backend_local_authority_finalize;
priv = POLKIT_BACKEND_LOCAL_GET_PRIVATE (backend);
g_type_class_add_private (klass, sizeof (PolkitBackendLocalAuthorityPrivate));
}
PolkitBackendLocal *
polkit_backend_local_new (void)
PolkitBackendLocalAuthority *
polkit_backend_local_authority_new (void)
{
PolkitBackendLocal *backend;
PolkitBackendLocalAuthority *local_authority;
backend = POLKIT_BACKEND_LOCAL (g_object_new (POLKIT_TYPE_BACKEND_LOCAL,
NULL));
local_authority = POLKIT_BACKEND_LOCAL_AUTHORITY (g_object_new (POLKIT_TYPE_BACKEND_LOCAL_AUTHORITY,
NULL));
return backend;
return local_authority;
}
/* ---------------------------------------------------------------------------------------------------- */
static void
authority_iface_handle_say_hello (PolkitAuthority *instance,
authority_iface_handle_say_hello (PolkitAuthority *authority,
const gchar *message,
EggDBusMethodInvocation *method_invocation)
{
......@@ -100,8 +110,10 @@ authority_iface_handle_say_hello (PolkitAuthority *instance,
g_free (result);
}
/* ---------------------------------------------------------------------------------------------------- */
static void
authority_iface_handle_enumerate_users (PolkitAuthority *instance,
authority_iface_handle_enumerate_users (PolkitAuthority *authority,
EggDBusMethodInvocation *method_invocation)
{
struct passwd *passwd;
......@@ -141,10 +153,39 @@ authority_iface_handle_enumerate_users (PolkitAuthority *instance,
g_list_free (list);
}
/* ---------------------------------------------------------------------------------------------------- */
static void
authority_iface_handle_enumerate_actions (PolkitAuthority *authority,
const gchar *locale,
EggDBusMethodInvocation *method_invocation)
{
PolkitBackendLocalAuthority *local_authority;
PolkitBackendLocalAuthorityPrivate *priv;
GList *list;
local_authority = POLKIT_BACKEND_LOCAL_AUTHORITY (authority);
priv = POLKIT_BACKEND_LOCAL_AUTHORITY_GET_PRIVATE (local_authority);
list = polkit_backend_action_pool_get_localized_actions (priv->action_pool,
locale);
polkit_authority_handle_enumerate_actions_finish (method_invocation,
list);
g_list_foreach (list, (GFunc) g_object_unref, NULL);
g_list_free (list);
}
/* ---------------------------------------------------------------------------------------------------- */
static void
authority_iface_init (PolkitAuthorityIface *authority_iface,
gpointer iface_data)
{
authority_iface->handle_say_hello = authority_iface_handle_say_hello;
authority_iface->handle_enumerate_users = authority_iface_handle_enumerate_users;
authority_iface->handle_say_hello = authority_iface_handle_say_hello;
authority_iface->handle_enumerate_users = authority_iface_handle_enumerate_users;
authority_iface->handle_enumerate_actions = authority_iface_handle_enumerate_actions;
}
/* ---------------------------------------------------------------------------------------------------- */
......@@ -25,27 +25,27 @@
#include <glib-object.h>
#ifndef __POLKIT_BACKEND_LOCAL_H
#define __POLKIT_BACKEND_LOCAL_H
#ifndef __POLKIT_BACKEND_LOCAL_AUTHORITY_H
#define __POLKIT_BACKEND_LOCAL_AUTHORITY_H
G_BEGIN_DECLS
#define POLKIT_TYPE_BACKEND_LOCAL (polkit_backend_local_get_type ())
#define POLKIT_BACKEND_LOCAL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_BACKEND_LOCAL, PolkitBackendLocal))
#define POLKIT_BACKEND_LOCAL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), POLKIT_TYPE_BACKEND_LOCAL, PolkitBackendLocalClass))
#define POLKIT_BACKEND_LOCAL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_BACKEND_LOCAL,PolkitBackendLocalClass))
#define POLKIT_IS_BACKEND_LOCAL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_BACKEND_LOCAL))
#define POLKIT_IS_BACKEND_LOCAL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_BACKEND_LOCAL))
#define POLKIT_TYPE_BACKEND_LOCAL_AUTHORITY (polkit_backend_local_authority_get_type ())
#define POLKIT_BACKEND_LOCAL_AUTHORITY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_BACKEND_LOCAL_AUTHORITY, PolkitBackendLocalAuthority))
#define POLKIT_BACKEND_LOCAL_AUTHORITY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), POLKIT_TYPE_BACKEND_LOCAL_AUTHORITY, PolkitBackendLocalAuthorityClass))
#define POLKIT_BACKEND_LOCAL_AUTHORITY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_BACKEND_LOCAL_AUTHORITY,PolkitBackendLocalAuthorityClass))
#define POLKIT_BACKEND_IS_LOCAL_AUTHORITY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_BACKEND_LOCAL_AUTHORITY))
#define POLKIT_BACKEND_IS_LOCAL_AUTHORITY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_BACKEND_LOCAL_AUTHORITY))
typedef struct _PolkitBackendLocal PolkitBackendLocal;
typedef struct _PolkitBackendLocalClass PolkitBackendLocalClass;
typedef struct _PolkitBackendLocalAuthority PolkitBackendLocalAuthority;
typedef struct _PolkitBackendLocalAuthorityClass PolkitBackendLocalAuthorityClass;
struct _PolkitBackendLocal
struct _PolkitBackendLocalAuthority
{
GObject parent_instance;
};
struct _PolkitBackendLocalClass
struct _PolkitBackendLocalAuthorityClass
{
GObjectClass parent_class;
......@@ -63,11 +63,11 @@ struct _PolkitBackendLocalClass
void (*_polkit_reserved8) (void);
};
GType polkit_backend_local_get_type (void) G_GNUC_CONST;
GType polkit_backend_local_authority_get_type (void) G_GNUC_CONST;
PolkitBackendLocal *polkit_backend_local_new (void);
PolkitBackendLocalAuthority *polkit_backend_local_authority_new (void);
G_END_DECLS
#endif /* __POLKIT_BACKEND_LOCAL_H */
#endif /* __POLKIT_BACKEND_LOCAL_AUTHORITY_H */
......@@ -30,7 +30,7 @@ static PolkitAuthority *
get_authority_backend (void)
{
/* TODO: use extension points etc. */
return POLKIT_AUTHORITY (polkit_backend_local_new ());
return POLKIT_AUTHORITY (polkit_backend_local_authority_new ());
}
int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment