introduce a PendingCall type to make all backend operations async
authorDavid Zeuthen <davidz@redhat.com>
Mon, 12 Jan 2009 21:06:24 +0000 (16:06 -0500)
committerDavid Zeuthen <davidz@redhat.com>
Mon, 12 Jan 2009 21:06:24 +0000 (16:06 -0500)
src/polkitbackend/Makefile.am
src/polkitbackend/polkitbackend.h
src/polkitbackend/polkitbackendauthority.c
src/polkitbackend/polkitbackendauthority.h
src/polkitbackend/polkitbackendlocalauthority.c
src/polkitbackend/polkitbackendpendingcall.c [new file with mode: 0644]
src/polkitbackend/polkitbackendpendingcall.h [new file with mode: 0644]
src/polkitbackend/polkitbackendprivate.h [new file with mode: 0644]
src/polkitbackend/polkitbackendserver.c
src/polkitbackend/polkitbackendtypes.h
src/programs/polkit.c

index 41ea29a..6e3e566 100644 (file)
@@ -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)
 
index 63090aa..84de7af 100644 (file)
@@ -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>
index 135dcd7..36d997d 100644 (file)
@@ -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);
 }
index 413f414..80e9725 100644 (file)
@@ -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
 
index 028adc7..94d0cbb 100644 (file)
@@ -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
diff --git a/src/polkitbackend/polkitbackendpendingcall.c b/src/polkitbackend/polkitbackendpendingcall.c
new file mode 100644 (file)
index 0000000..baefb25
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * 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);
+}
+
diff --git a/src/polkitbackend/polkitbackendpendingcall.h b/src/polkitbackend/polkitbackendpendingcall.h
new file mode 100644 (file)
index 0000000..de26e52
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * 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 */
+
diff --git a/src/polkitbackend/polkitbackendprivate.h b/src/polkitbackend/polkitbackendprivate.h
new file mode 100644 (file)
index 0000000..e43635c
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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);
+
+EggDBusMethodInvocation  *_polkit_backend_pending_call_get_method_invocation (PolkitBackendPendingCall *pending_call);
+
+#endif /* __POLKIT_BACKEND_PRIVATE_H */
index 05125d1..8cc25c6 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "polkitbackendauthority.h"
 #include "polkitbackendserver.h"
+#include "polkitbackendprivate.h"
 
 struct _PolkitBackendServer
 {
@@ -90,20 +91,19 @@ authority_handle_enumerate_actions (_PolkitAuthority        *instance,
                                     EggDBusMethodInvocation *method_invocation)
 {
   PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance);
-  EggDBusArraySeq *array;
-  GError *error;
-  GList *actions;
-  GList *l;
+  PolkitBackendPendingCall *pending_call;
 
-  error = NULL;
-  actions = polkit_backend_authority_enumerate_actions (server->authority, locale, &error);
+  pending_call = _polkit_backend_pending_call_new (method_invocation, server);
 
-  if (error != NULL)
-    {
-      egg_dbus_method_invocation_return_gerror (method_invocation, error);
-      g_error_free (error);
-      goto out;
-    }
+  polkit_backend_authority_enumerate_actions (server->authority, locale, pending_call);
+}
+
+void
+polkit_backend_authority_enumerate_actions_finish (PolkitBackendPendingCall *pending_call,
+                                                   GList                    *actions)
+{
+  EggDBusArraySeq *array;
+  GList *l;
 
   array = egg_dbus_array_seq_new (_POLKIT_TYPE_ACTION_DESCRIPTION, (GDestroyNotify) g_object_unref, NULL, NULL);
 
@@ -116,15 +116,15 @@ authority_handle_enumerate_actions (_PolkitAuthority        *instance,
       egg_dbus_array_seq_add (array, real);
     }
 
-  _polkit_authority_handle_enumerate_actions_finish (method_invocation, array);
+  _polkit_authority_handle_enumerate_actions_finish (_polkit_backend_pending_call_get_method_invocation (pending_call),
+                                                     array);
 
   g_object_unref (array);
 
   g_list_foreach (actions, (GFunc) g_object_unref, NULL);
   g_list_free (actions);
 
- out:
-  ;
+  g_object_unref (pending_call);
 }
 
 static void
@@ -132,24 +132,23 @@ authority_handle_enumerate_users (_PolkitAuthority        *instance,
                                   EggDBusMethodInvocation *method_invocation)
 {
   PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance);
-  EggDBusArraySeq *array;
-  GError *error;
-  GList *subjects;
-  GList *l;
+  PolkitBackendPendingCall *pending_call;
 
-  error = NULL;
-  subjects = polkit_backend_authority_enumerate_users (server->authority, &error);
+  pending_call = _polkit_backend_pending_call_new (method_invocation, server);
 
-  if (error != NULL)
-    {
-      egg_dbus_method_invocation_return_gerror (method_invocation, error);
-      g_error_free (error);
-      goto out;
-    }
+  polkit_backend_authority_enumerate_users (server->authority, pending_call);
+}
+
+void
+polkit_backend_authority_enumerate_users_finish (PolkitBackendPendingCall *pending_call,
+                                                 GList                    *users)
+{
+  EggDBusArraySeq *array;
+  GList *l;
 
   array = egg_dbus_array_seq_new (_POLKIT_TYPE_SUBJECT, (GDestroyNotify) g_object_unref, NULL, NULL);
 
-  for (l = subjects; l != NULL; l = l->next)
+  for (l = users; l != NULL; l = l->next)
     {
       PolkitSubject *subject = POLKIT_SUBJECT (l->data);
       _PolkitSubject *real;
@@ -158,15 +157,13 @@ authority_handle_enumerate_users (_PolkitAuthority        *instance,
       egg_dbus_array_seq_add (array, real);
     }
 
-  _polkit_authority_handle_enumerate_users_finish (method_invocation, array);
+  _polkit_authority_handle_enumerate_users_finish (_polkit_backend_pending_call_get_method_invocation (pending_call),
+                                                   array);
 
   g_object_unref (array);
 
-  g_list_foreach (subjects, (GFunc) g_object_unref, NULL);
-  g_list_free (subjects);
-
- out:
-  ;
+  g_list_foreach (users, (GFunc) g_object_unref, NULL);
+  g_list_free (users);
 }
 
 static void
@@ -174,24 +171,23 @@ authority_handle_enumerate_groups (_PolkitAuthority        *instance,
                                    EggDBusMethodInvocation *method_invocation)
 {
   PolkitBackendServer *server = POLKIT_BACKEND_SERVER (instance);
-  EggDBusArraySeq *array;
-  GError *error;
-  GList *subjects;
-  GList *l;
+  PolkitBackendPendingCall *pending_call;
 
-  error = NULL;
-  subjects = polkit_backend_authority_enumerate_groups (server->authority, &error);
+  pending_call = _polkit_backend_pending_call_new (method_invocation, server);
 
-  if (error != NULL)
-    {
-      egg_dbus_method_invocation_return_gerror (method_invocation, error);
-      g_error_free (error);
-      goto out;
-    }
+  polkit_backend_authority_enumerate_groups (server->authority, pending_call);
+}
+
+void
+polkit_backend_authority_enumerate_groups_finish (PolkitBackendPendingCall *pending_call,
+                                                  GList                    *groups)
+{
+  EggDBusArraySeq *array;
+  GList *l;
 
   array = egg_dbus_array_seq_new (_POLKIT_TYPE_SUBJECT, (GDestroyNotify) g_object_unref, NULL, NULL);
 
-  for (l = subjects; l != NULL; l = l->next)
+  for (l = groups; l != NULL; l = l->next)
     {
       PolkitSubject *subject = POLKIT_SUBJECT (l->data);
       _PolkitSubject *real;
@@ -200,15 +196,13 @@ authority_handle_enumerate_groups (_PolkitAuthority        *instance,
       egg_dbus_array_seq_add (array, real);
     }
 
-  _polkit_authority_handle_enumerate_groups_finish (method_invocation, array);
+  _polkit_authority_handle_enumerate_groups_finish (_polkit_backend_pending_call_get_method_invocation (pending_call),
+                                                    array);
 
   g_object_unref (array);
 
-  g_list_foreach (subjects, (GFunc) g_object_unref, NULL);
-  g_list_free (subjects);
-
- out:
-  ;
+  g_list_foreach (groups, (GFunc) g_object_unref, NULL);
+  g_list_free (groups);
 }
 
 static void
index 715adda..a1ebd8e 100644 (file)
@@ -27,6 +27,9 @@
 struct _PolkitBackendAuthority;
 typedef struct _PolkitBackendAuthority PolkitBackendAuthority;
 
+struct _PolkitBackendPendingCall;
+typedef struct _PolkitBackendPendingCall PolkitBackendPendingCall;
+
 struct _PolkitBackendServer;
 typedef struct _PolkitBackendServer PolkitBackendServer;
 
index c372eb0..d436338 100644 (file)
@@ -48,6 +48,8 @@ static gboolean list_actions (void);
 static gboolean list_users (void);
 static gboolean list_groups (void);
 
+static gboolean check (void);
+
 static gboolean show_action (const gchar *action_id);
 
 static void
@@ -210,8 +212,13 @@ main (int argc, char *argv[])
     }
   else if (opt_check)
     {
-      g_print ("subject '%s' action-id '%s'\n", polkit_subject_to_string (subject), action_id);
-      g_assert (FALSE);
+      if (subject == NULL || action_id == NULL)
+        {
+          usage (argc, argv);
+          goto out;
+        }
+
+      ret = check ();
     }
   else
     {
@@ -450,3 +457,38 @@ list_groups (void)
  out:
   return ret;
 }
+
+static gboolean
+check (void)
+{
+  PolkitAuthorizationResult result;
+  PolkitAuthorizationClaim *claim;
+  GError *error;
+
+  error = NULL;
+  claim = NULL;
+  result = POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED;
+
+  claim = polkit_authorization_claim_new (subject,
+                                          action_id);
+
+  result = polkit_authority_check_claim_sync (authority,
+                                              claim,
+                                              NULL,
+                                              &error);
+  if (error != NULL)
+    {
+      g_printerr ("Error checking authorization claim: %s\n", error->message);
+      g_error_free (error);
+      goto out;
+    }
+
+  g_debug ("result = %d", result);
+
+ out:
+  if (claim != NULL)
+    g_object_unref (claim);
+
+  return result == POLKIT_AUTHORIZATION_RESULT_AUTHORIZED;
+}
+