Commit 454d6da4 authored by David Zeuthen's avatar David Zeuthen

introduce a PendingCall type to make all backend operations async

parent 4b773b13
......@@ -25,15 +25,18 @@ libpolkit_backend_1include_HEADERS = \
polkitbackendauthority.h \
polkitbackendlocalauthority.h \
polkitbackendactionpool.h \
polkitbackendpendingcall.h \
polkitbackendserver.h \
$(NULL)
libpolkit_backend_1_la_SOURCES = \
polkitbackend.h \
polkitbackendtypes.h \
polkitbackendprivate.h \
polkitbackendauthority.h polkitbackendauthority.c \
polkitbackendlocalauthority.h polkitbackendlocalauthority.c \
polkitbackendactionpool.h polkitbackendactionpool.c \
polkitbackendpendingcall.h polkitbackendpendingcall.c \
polkitbackendserver.h polkitbackendserver.c \
$(NULL)
......
......@@ -24,6 +24,7 @@
#define _POLKIT_BACKEND_INSIDE_POLKIT_BACKEND_H 1
#include <polkitbackend/polkitbackendtypes.h>
#include <polkitbackend/polkitbackendpendingcall.h>
#include <polkitbackend/polkitbackendauthority.h>
#include <polkitbackend/polkitbackendlocalauthority.h>
#include <polkitbackend/polkitbackendactionpool.h>
......
......@@ -38,36 +38,36 @@ polkit_backend_authority_class_init (PolkitBackendAuthorityClass *klass)
{
}
GList *
polkit_backend_authority_enumerate_actions (PolkitBackendAuthority *authority,
const gchar *locale,
GError **error)
void
polkit_backend_authority_enumerate_actions (PolkitBackendAuthority *authority,
const gchar *locale,
PolkitBackendPendingCall *pending_call)
{
PolkitBackendAuthorityClass *klass;
klass = POLKIT_BACKEND_AUTHORITY_GET_CLASS (authority);
return klass->enumerate_actions (authority, locale, error);
klass->enumerate_actions (authority, locale, pending_call);
}
GList *
polkit_backend_authority_enumerate_users (PolkitBackendAuthority *authority,
GError **error)
void
polkit_backend_authority_enumerate_users (PolkitBackendAuthority *authority,
PolkitBackendPendingCall *pending_call)
{
PolkitBackendAuthorityClass *klass;
klass = POLKIT_BACKEND_AUTHORITY_GET_CLASS (authority);
return klass->enumerate_users (authority, error);
klass->enumerate_users (authority, pending_call);
}
GList *
polkit_backend_authority_enumerate_groups (PolkitBackendAuthority *authority,
GError **error)
void
polkit_backend_authority_enumerate_groups (PolkitBackendAuthority *authority,
PolkitBackendPendingCall *pending_call)
{
PolkitBackendAuthorityClass *klass;
klass = POLKIT_BACKEND_AUTHORITY_GET_CLASS (authority);
return klass->enumerate_groups (authority, error);
klass->enumerate_groups (authority, pending_call);
}
......@@ -51,15 +51,15 @@ struct _PolkitBackendAuthorityClass
/*< public >*/
GList * (*enumerate_actions) (PolkitBackendAuthority *authority,
const gchar *locale,
GError **error);
void (*enumerate_actions) (PolkitBackendAuthority *authority,
const gchar *locale,
PolkitBackendPendingCall *pending_call);
GList * (*enumerate_users) (PolkitBackendAuthority *authority,
GError **error);
void (*enumerate_users) (PolkitBackendAuthority *authority,
PolkitBackendPendingCall *pending_call);
GList * (*enumerate_groups) (PolkitBackendAuthority *authority,
GError **error);
void (*enumerate_groups) (PolkitBackendAuthority *authority,
PolkitBackendPendingCall *pending_call);
/*< private >*/
/* Padding for future expansion */
......@@ -73,17 +73,26 @@ struct _PolkitBackendAuthorityClass
void (*_polkit_reserved8) (void);
};
GType polkit_backend_authority_get_type (void) G_GNUC_CONST;
GType polkit_backend_authority_get_type (void) G_GNUC_CONST;
GList *polkit_backend_authority_enumerate_actions (PolkitBackendAuthority *authority,
const gchar *locale,
GError **error);
void polkit_backend_authority_enumerate_actions (PolkitBackendAuthority *authority,
const gchar *locale,
PolkitBackendPendingCall *pending_call);
GList *polkit_backend_authority_enumerate_users (PolkitBackendAuthority *authority,
GError **error);
void polkit_backend_authority_enumerate_users (PolkitBackendAuthority *authority,
PolkitBackendPendingCall *pending_call);
GList *polkit_backend_authority_enumerate_groups (PolkitBackendAuthority *authority,
GError **error);
void polkit_backend_authority_enumerate_groups (PolkitBackendAuthority *authority,
PolkitBackendPendingCall *pending_call);
void polkit_backend_authority_enumerate_actions_finish (PolkitBackendPendingCall *pending_call,
GList *actions);
void polkit_backend_authority_enumerate_users_finish (PolkitBackendPendingCall *pending_call,
GList *users);
void polkit_backend_authority_enumerate_groups_finish (PolkitBackendPendingCall *pending_call,
GList *groups);
G_END_DECLS
......
......@@ -27,6 +27,7 @@
#include <polkit/polkit.h>
#include "polkitbackendlocalauthority.h"
#include "polkitbackendactionpool.h"
#include "polkitbackendpendingcall.h"
typedef struct
{
......@@ -34,15 +35,15 @@ typedef struct
} PolkitBackendLocalAuthorityPrivate;
static GList *polkit_backend_local_authority_enumerate_actions (PolkitBackendAuthority *authority,
const gchar *locale,
GError **error);
static void polkit_backend_local_authority_enumerate_actions (PolkitBackendAuthority *authority,
const gchar *locale,
PolkitBackendPendingCall *pending_call);
static GList *polkit_backend_local_authority_enumerate_users (PolkitBackendAuthority *authority,
GError **error);
static void polkit_backend_local_authority_enumerate_users (PolkitBackendAuthority *authority,
PolkitBackendPendingCall *pending_call);
static GList *polkit_backend_local_authority_enumerate_groups (PolkitBackendAuthority *authority,
GError **error);
static void polkit_backend_local_authority_enumerate_groups (PolkitBackendAuthority *authority,
PolkitBackendPendingCall *pending_call);
G_DEFINE_TYPE (PolkitBackendLocalAuthority, polkit_backend_local_authority, POLKIT_BACKEND_TYPE_AUTHORITY);
......@@ -103,23 +104,27 @@ polkit_backend_local_authority_new (void)
/* ---------------------------------------------------------------------------------------------------- */
static GList *
polkit_backend_local_authority_enumerate_actions (PolkitBackendAuthority *authority,
const gchar *locale,
GError **error)
static void
polkit_backend_local_authority_enumerate_actions (PolkitBackendAuthority *authority,
const gchar *locale,
PolkitBackendPendingCall *pending_call)
{
PolkitBackendLocalAuthority *local_authority;
PolkitBackendLocalAuthorityPrivate *priv;
GList *actions;
local_authority = POLKIT_BACKEND_LOCAL_AUTHORITY (authority);
priv = POLKIT_BACKEND_LOCAL_AUTHORITY_GET_PRIVATE (local_authority);
return polkit_backend_action_pool_get_all_actions (priv->action_pool, locale);
actions = polkit_backend_action_pool_get_all_actions (priv->action_pool, locale);
polkit_backend_authority_enumerate_actions_finish (pending_call,
actions);
}
static GList *
polkit_backend_local_authority_enumerate_users (PolkitBackendAuthority *authority,
GError **error)
static void
polkit_backend_local_authority_enumerate_users (PolkitBackendAuthority *authority,
PolkitBackendPendingCall *pending_call)
{
PolkitBackendLocalAuthority *local_authority;
PolkitBackendLocalAuthorityPrivate *priv;
......@@ -134,11 +139,11 @@ polkit_backend_local_authority_enumerate_users (PolkitBackendAuthority *authori
passwd = getpwent ();
if (passwd == NULL)
{
g_set_error (error,
POLKIT_ERROR,
POLKIT_ERROR_FAILED,
"getpwent failed: %s",
strerror (errno));
polkit_backend_pending_call_return_error (pending_call,
POLKIT_ERROR,
POLKIT_ERROR_FAILED,
"getpwent failed: %s",
strerror (errno));
goto out;
}
......@@ -155,13 +160,15 @@ polkit_backend_local_authority_enumerate_users (PolkitBackendAuthority *authori
list = g_list_reverse (list);
polkit_backend_authority_enumerate_users_finish (pending_call, list);
out:
return list;
;
}
static GList *
polkit_backend_local_authority_enumerate_groups (PolkitBackendAuthority *authority,
GError **error)
static void
polkit_backend_local_authority_enumerate_groups (PolkitBackendAuthority *authority,
PolkitBackendPendingCall *pending_call)
{
PolkitBackendLocalAuthority *local_authority;
PolkitBackendLocalAuthorityPrivate *priv;
......@@ -176,11 +183,11 @@ polkit_backend_local_authority_enumerate_groups (PolkitBackendAuthority *author
group = getgrent ();
if (group == NULL)
{
g_set_error (error,
POLKIT_ERROR,
POLKIT_ERROR_FAILED,
"getgrent failed: %s",
strerror (errno));
polkit_backend_pending_call_return_error (pending_call,
POLKIT_ERROR,
POLKIT_ERROR_FAILED,
"getpwent failed: %s",
strerror (errno));
goto out;
}
......@@ -197,105 +204,8 @@ polkit_backend_local_authority_enumerate_groups (PolkitBackendAuthority *author
list = g_list_reverse (list);
out:
return list;
}
#if 0
/* ---------------------------------------------------------------------------------------------------- */
static void
authority_iface_handle_say_hello (PolkitAuthority *authority,
const gchar *message,
EggDBusMethodInvocation *method_invocation)
{
gchar *result;
result = g_strdup_printf ("You said '%s' to the AUTHORITY!", message);
polkit_authority_handle_say_hello_finish (method_invocation,
result);
g_free (result);
}
/* ---------------------------------------------------------------------------------------------------- */
static void
authority_iface_handle_enumerate_users (PolkitAuthority *authority,
EggDBusMethodInvocation *method_invocation)
{
struct passwd *passwd;
GList *list;
list = NULL;
passwd = getpwent ();
if (passwd == NULL)
{
egg_dbus_method_invocation_return_error (method_invocation,
POLKIT_ERROR,
POLKIT_ERROR_FAILED,
"getpwent failed: %s",
strerror (errno));
goto out;
}
do
{
PolkitSubject *subject;
subject = polkit_subject_new_for_unix_user (passwd->pw_uid);
list = g_list_prepend (list, subject);
}
while ((passwd = getpwent ()) != NULL);
endpwent ();
list = g_list_reverse (list);
polkit_authority_handle_enumerate_users_finish (method_invocation,
list);
polkit_backend_authority_enumerate_groups_finish (pending_call, list);
out:
g_list_foreach (list, (GFunc) g_object_unref, NULL);
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_all_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_enumerate_actions = authority_iface_handle_enumerate_actions;
}
/* ---------------------------------------------------------------------------------------------------- */
#endif
/*
* 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 <polkit/polkit.h>
#include "polkitbackendpendingcall.h"
#include "polkitbackendprivate.h"
typedef struct
{
EggDBusMethodInvocation *method_invocation;
PolkitBackendServer *server;
} PolkitBackendPendingCallPrivate;
G_DEFINE_TYPE (PolkitBackendPendingCall, polkit_backend_pending_call, G_TYPE_OBJECT);
#define POLKIT_BACKEND_PENDING_CALL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), POLKIT_BACKEND_TYPE_PENDING_CALL, PolkitBackendPendingCallPrivate))
static void
polkit_backend_pending_call_init (PolkitBackendPendingCall *pending_call)
{
PolkitBackendPendingCallPrivate *priv;
priv = POLKIT_BACKEND_PENDING_CALL_GET_PRIVATE (pending_call);
}
static void
polkit_backend_pending_call_finalize (GObject *object)
{
PolkitBackendPendingCall *pending_call;
PolkitBackendPendingCallPrivate *priv;
pending_call = POLKIT_BACKEND_PENDING_CALL (object);
priv = POLKIT_BACKEND_PENDING_CALL_GET_PRIVATE (pending_call);
g_object_unref (priv->method_invocation);
g_object_unref (priv->server);
G_OBJECT_CLASS (polkit_backend_pending_call_parent_class)->finalize (object);
}
static void
polkit_backend_pending_call_class_init (PolkitBackendPendingCallClass *klass)
{
GObjectClass *gobject_class;
gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = polkit_backend_pending_call_finalize;
g_type_class_add_private (klass, sizeof (PolkitBackendPendingCallPrivate));
}
PolkitBackendPendingCall *
_polkit_backend_pending_call_new (EggDBusMethodInvocation *method_invocation,
PolkitBackendServer *server)
{
PolkitBackendPendingCall *pending_call;
PolkitBackendPendingCallPrivate *priv;
pending_call = POLKIT_BACKEND_PENDING_CALL (g_object_new (POLKIT_BACKEND_TYPE_PENDING_CALL,
NULL));
priv = POLKIT_BACKEND_PENDING_CALL_GET_PRIVATE (pending_call);
priv->method_invocation = g_object_ref (method_invocation);
priv->server = g_object_ref (server);
return pending_call;
}
PolkitBackendServer *
polkit_backend_pending_call_get_server (PolkitBackendPendingCall *pending_call)
{
PolkitBackendPendingCallPrivate *priv;
priv = POLKIT_BACKEND_PENDING_CALL_GET_PRIVATE (pending_call);
return priv->server;
}
EggDBusMethodInvocation *
_polkit_backend_pending_call_get_method_invocation (PolkitBackendPendingCall *pending_call)
{
PolkitBackendPendingCallPrivate *priv;
priv = POLKIT_BACKEND_PENDING_CALL_GET_PRIVATE (pending_call);
return priv->method_invocation;
}
PolkitSubject *
polkit_backend_pending_call_get_caller (PolkitBackendPendingCall *pending_call)
{
/* TODO: implement */
return NULL;
}
void
polkit_backend_pending_call_return_gerror (PolkitBackendPendingCall *pending_call,
GError *error)
{
PolkitBackendPendingCallPrivate *priv;
priv = POLKIT_BACKEND_PENDING_CALL_GET_PRIVATE (pending_call);
egg_dbus_method_invocation_return_gerror (priv->method_invocation,
error);
g_object_unref (pending_call);
}
void
polkit_backend_pending_call_return_error (PolkitBackendPendingCall *pending_call,
GQuark domain,
gint code,
const gchar *format,
...)
{
GError *error;
va_list va_args;
gchar *literal_message;
va_start (va_args, format);
literal_message = g_strdup_vprintf (format, va_args);
error = g_error_new_literal (domain,
code,
literal_message);
polkit_backend_pending_call_return_gerror (pending_call, error);
g_error_free (error);
g_free (literal_message);
va_end (va_args);
}
/*
* 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_PENDING_CALL_H
#define __POLKIT_BACKEND_PENDING_CALL_H
#include <glib-object.h>
#include "polkitbackendtypes.h"
G_BEGIN_DECLS
#define POLKIT_BACKEND_TYPE_PENDING_CALL (polkit_backend_pending_call_get_type ())
#define POLKIT_BACKEND_PENDING_CALL(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_BACKEND_TYPE_PENDING_CALL, PolkitBackendPendingCall))
#define POLKIT_BACKEND_PENDING_CALL_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), POLKIT_BACKEND_TYPE_PENDING_CALL, PolkitBackendPendingCallClass))
#define POLKIT_BACKEND_PENDING_CALL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_BACKEND_TYPE_PENDING_CALL,PolkitBackendPendingCallClass))
#define POLKIT_BACKEND_IS_PENDING_CALL(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_BACKEND_TYPE_PENDING_CALL))
#define POLKIT_BACKEND_IS_PENDING_CALL_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_BACKEND_TYPE_PENDING_CALL))
#if 0
typedef struct _PolkitBackendPendingCall PolkitBackendPendingCall;
#endif
typedef struct _PolkitBackendPendingCallClass PolkitBackendPendingCallClass;
struct _PolkitBackendPendingCall
{
GObject parent_instance;
};
struct _PolkitBackendPendingCallClass
{
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_pending_call_get_type (void) G_GNUC_CONST;
PolkitSubject *polkit_backend_pending_call_get_caller (PolkitBackendPendingCall *pending_call);
PolkitBackendServer *polkit_backend_pending_call_get_server (PolkitBackendPendingCall *pending_call);
void polkit_backend_pending_call_return_error (PolkitBackendPendingCall *pending_call,
GQuark domain,
gint code,
const gchar *format,
...);
void polkit_backend_pending_call_return_gerror (PolkitBackendPendingCall *pending_call,
GError *error);
G_END_DECLS
#endif /* __POLKIT_BACKEND_PENDING_CALL_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>
*/
#ifndef __POLKIT_BACKEND_PRIVATE_H
#define __POLKIT_BACKEND_PRIVATE_H
#include <polkit/_polkitbindings.h>
#include "polkitbackendpendingcall.h"
#include "polkitbackendserver.h"
PolkitBackendPendingCall *_polkit_backend_pending_call_new (EggDBusMethodInvocation *method_invocation,
PolkitBackendServer *server);