Commit 8cb60d1f authored by David Zeuthen's avatar David Zeuthen

change code style to be like GLib and generate error domain

Also port to use non-reffing structs in EggDBus HEAD.
parent 516935ec
......@@ -2,9 +2,19 @@
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<!-- User defined struct -->
<annotation name="org.gtk.EggDBus.DeclareStruct" value="Subject">
<annotation name="org.gtk.EggDBus.Struct.Signature" value="(sa{sv})"/>
<!-- User defined struct for Subjects -->
<annotation name="org.gtk.EggDBus.DeclareStruct" value="Subject">
<annotation name="org.gtk.EggDBus.Struct.Signature" value="(sa{sv})"/>
</annotation>
<!-- The error domain used -->
<annotation name="org.gtk.EggDBus.DeclareErrorDomain" value="Error">
<annotation name="org.gtk.EggDBus.ErrorDomain.Member" value="org.freedesktop.PolicyKit1.Error.Failed">
<annotation name="org.gtk.EggDBus.DocString" value="The operation failed"/>
</annotation>
<annotation name="org.gtk.EggDBus.ErrorDomain.Member" value="org.freedesktop.PolicyKit1.Error.NotSupported">
<annotation name="org.gtk.EggDBus.DocString" value="Operation is not supported"/>
</annotation>
</annotation>
<interface name="org.freedesktop.PolicyKit1.Authority">
......
......@@ -18,6 +18,7 @@ BUILT_SOURCES = \
polkitbindings.h polkitbindings.c \
polkitbindingstypes.h \
polkitauthority.h polkitauthority.c \
polkiterror.h polkiterror.c \
polkitbindingsmarshal.h polkitbindingsmarshal.c \
polkitbindingsmarshal.list \
$(NULL)
......@@ -53,7 +54,6 @@ libpolkit_gobject_1_la_SOURCES = \
polkitactiondescription.h polkitactiondescription.c \
polkitauthorizationclaim.h polkitauthorizationclaim.c \
polkitauthorizationresult.h polkitauthorizationresult.c \
polkiterror.h polkiterror.c \
polkitsubject.h polkitsubject.c \
$(BUILT_SOURCES) \
$(NULL)
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Red Hat, Inc.
*
......
This diff is collapsed.
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Red Hat, Inc.
*
......@@ -46,13 +44,13 @@ typedef struct _PolkitActionDescriptionPrivate PolkitActionDescriptionPrivate;
struct _PolkitActionDescription
{
GObject parent_instance;
PolkitActionDescriptionPrivate *priv;
GObject parent_instance;
PolkitActionDescriptionPrivate *priv;
};
struct _PolkitActionDescriptionClass
{
GObjectClass parent_class;
GObjectClass parent_class;
};
GType polkit_action_description_get_type (void) G_GNUC_CONST;
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Red Hat, Inc.
*
......@@ -38,24 +36,27 @@ static PolkitAuthority *the_authority = NULL;
PolkitAuthority *
polkit_authority_get (void)
{
PolkitAuthority *authority;
PolkitAuthority *authority;
polkit_bindings_register_types (); /* TODO: use __attribute ((constructor)) */
polkit_bindings_register_types (); /* TODO: use __attribute ((constructor)) */
if (the_authority != NULL) {
authority = g_object_ref (the_authority);
} else {
EggDBusConnection *connection;
if (the_authority != NULL)
{
authority = g_object_ref (the_authority);
}
else
{
EggDBusConnection *connection;
connection = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM);
authority = POLKIT_AUTHORITY (egg_dbus_connection_get_proxy (connection,
"org.freedesktop.PolicyKit1",
"/org/freedesktop/PolicyKit1/Authority"));
connection = egg_dbus_connection_get_for_bus (EGG_DBUS_BUS_TYPE_SYSTEM);
authority = POLKIT_AUTHORITY (egg_dbus_connection_get_proxy (connection,
"org.freedesktop.PolicyKit1",
"/org/freedesktop/PolicyKit1/Authority"));
/* TODO: take a weak reference and set the_authority to NULL on destruction */
/* TODO: take a weak reference and set the_authority to NULL on destruction */
/* TODO: unref connection since authority holds a reference? */
}
/* TODO: unref connection since authority holds a reference? */
}
return authority;
return authority;
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Red Hat, Inc.
*
......
This diff is collapsed.
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Red Hat, Inc.
*
......@@ -46,13 +44,13 @@ typedef struct _PolkitAuthorizationClaimPrivate PolkitAuthorizationClaimPrivate;
struct _PolkitAuthorizationClaim
{
GObject parent_instance;
PolkitAuthorizationClaimPrivate *priv;
GObject parent_instance;
PolkitAuthorizationClaimPrivate *priv;
};
struct _PolkitAuthorizationClaimClass
{
GObjectClass parent_class;
GObjectClass parent_class;
};
GType polkit_authorization_claim_get_type (void) G_GNUC_CONST;
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Red Hat, Inc.
*
......@@ -39,17 +37,17 @@
GType
polkit_authorization_result_get_type (void)
{
static GType etype = 0;
static GType etype = 0;
if (etype == 0)
{
static const GEnumValue values[] = {
ENUM_ENTRY (POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED, "NotAuthorized"),
ENUM_ENTRY (POLKIT_AUTHORIZATION_RESULT_AUTHORIZED, "Authorized"),
ENUM_ENTRY (POLKIT_AUTHORIZATION_RESULT_CHALLENGE, "Challenge"),
{ 0, 0, 0 }
};
etype = g_enum_register_static ("PolkitAuthorizationResult", values);
}
return etype;
if (etype == 0)
{
static const GEnumValue values[] = {
ENUM_ENTRY (POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED, "NotAuthorized"),
ENUM_ENTRY (POLKIT_AUTHORIZATION_RESULT_AUTHORIZED, "Authorized"),
ENUM_ENTRY (POLKIT_AUTHORIZATION_RESULT_CHALLENGE, "Challenge"),
{ 0, 0, 0 }
};
etype = g_enum_register_static ("PolkitAuthorizationResult", values);
}
return etype;
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Red Hat, Inc.
*
......@@ -43,9 +41,9 @@ G_BEGIN_DECLS
* The possible results when checking whether a claim is authorized.
*/
typedef enum {
POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED,
POLKIT_AUTHORIZATION_RESULT_AUTHORIZED,
POLKIT_AUTHORIZATION_RESULT_CHALLENGE
POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED,
POLKIT_AUTHORIZATION_RESULT_AUTHORIZED,
POLKIT_AUTHORIZATION_RESULT_CHALLENGE
} PolkitAuthorizationResult;
GType polkit_authorization_result_get_type (void) G_GNUC_CONST;
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/*
* 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/polkiterror.h>
/**
* SECTION:polkiterror
* @title: PolkitError
* @short_description: Error helper functions
* @include: polkit/polkit.h
*
* Contains helper functions for reporting errors to the user.
**/
/**
* polkit_error_quark:
*
* Gets the #PolkitError Quark.
*
* Return value: a #GQuark.
**/
GQuark
polkit_error_quark (void)
{
return g_quark_from_static_string ("g-polkit-error-quark");
}
#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
GType
polkit_error_get_type (void)
{
static GType etype = 0;
if (etype == 0)
{
static const GEnumValue values[] = {
ENUM_ENTRY (POLKIT_ERROR_FAILED, "Failed"),
ENUM_ENTRY (POLKIT_ERROR_NOT_SUPPORTED, "NotSupported"),
{ 0, 0, 0 }
};
g_assert (POLKIT_ERROR_NUM_ERRORS == G_N_ELEMENTS (values) - 1);
etype = g_enum_register_static ("PolkitErrorEnum", values);
}
return etype;
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: David Zeuthen <davidz@redhat.com>
*/
#if !defined (_POLKIT_COMPILATION) && !defined(_POLKIT_INSIDE_POLKIT_H)
#error "Only <polkit/polkit.h> can be included directly, this file may disappear or change contents."
#endif
#ifndef __POLKIT_ERROR_H
#define __POLKIT_ERROR_H
#include <glib-object.h>
G_BEGIN_DECLS
#define POLKIT_TYPE_ERROR (polkit_error_get_type ())
/**
* POLKIT_ERROR:
*
* Error domain for PolicyKit. Errors in this domain will be from the
* #PolkitErrorEnum enumeration. See #GError for more information on
* error domains.
**/
#define POLKIT_ERROR polkit_error_quark()
GQuark polkit_error_quark (void);
GType polkit_error_get_type (void) G_GNUC_CONST;
/**
* PolkitErrorEnum:
* @POLKIT_ERROR_FAILED: The operation failed.
* @POLKIT_ERROR_NOT_SUPPORTED: Operation not supported by backend.
*
* Error codes returned by PolicyKit functions.
*/
typedef enum {
POLKIT_ERROR_FAILED,
POLKIT_ERROR_NOT_SUPPORTED,
POLKIT_ERROR_NUM_ERRORS
} PolkitErrorEnum;
G_END_DECLS
#endif /* __POLKIT_ERROR_H */
......@@ -179,7 +179,7 @@ polkit_subject_new_for_unix_group (gid_t unix_group_id)
PolkitSubjectKind
polkit_subject_get_kind (PolkitSubject *subject)
{
gchar *kind_str;
const gchar *kind_str;
PolkitSubjectKind kind;
g_return_val_if_fail (POLKIT_IS_SUBJECT (subject), -1);
......@@ -201,8 +201,6 @@ polkit_subject_get_kind (PolkitSubject *subject)
kind = -1;
}
g_free (kind_str);
return kind;
}
......@@ -288,8 +286,6 @@ polkit_subject_unix_process_get_id (PolkitSubject *subject)
variant = g_hash_table_lookup (value, "unix-process-id");
pid = (pid_t) egg_dbus_variant_get_uint32 (variant);
egg_dbus_hash_table_unref (value);
return pid;
}
......@@ -319,8 +315,6 @@ polkit_subject_unix_user_get_id (PolkitSubject *subject)
variant = g_hash_table_lookup (value, "unix-user-id");
uid = (uid_t) egg_dbus_variant_get_uint32 (variant);
egg_dbus_hash_table_unref (value);
return uid;
}
......@@ -350,8 +344,6 @@ polkit_subject_unix_group_get_id (PolkitSubject *subject)
variant = g_hash_table_lookup (value, "unix-group-id");
gid = (gid_t) egg_dbus_variant_get_uint32 (variant);
egg_dbus_hash_table_unref (value);
return gid;
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Red Hat, Inc.
*
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Red Hat, Inc.
*
......@@ -32,7 +30,7 @@
typedef struct
{
guint foo;
guint foo;
} PolkitBackendLocalPrivate;
static void authority_iface_init (PolkitAuthorityIface *authority_iface,
......@@ -48,43 +46,43 @@ G_DEFINE_TYPE_WITH_CODE (PolkitBackendLocal, polkit_backend_local, G_TYPE_OBJECT
static void
polkit_backend_local_finalize (GObject *object)
{
PolkitBackendLocal *backend;
PolkitBackendLocalPrivate *priv;
PolkitBackendLocal *backend;
PolkitBackendLocalPrivate *priv;
backend = POLKIT_BACKEND_LOCAL (object);
priv = POLKIT_BACKEND_LOCAL_GET_PRIVATE (backend);
backend = POLKIT_BACKEND_LOCAL (object);
priv = POLKIT_BACKEND_LOCAL_GET_PRIVATE (backend);
G_OBJECT_CLASS (polkit_backend_local_parent_class)->finalize (object);
G_OBJECT_CLASS (polkit_backend_local_parent_class)->finalize (object);
}
static void
polkit_backend_local_class_init (PolkitBackendLocalClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = polkit_backend_local_finalize;
gobject_class->finalize = polkit_backend_local_finalize;
g_type_class_add_private (klass, sizeof (PolkitBackendLocalPrivate));
g_type_class_add_private (klass, sizeof (PolkitBackendLocalPrivate));
}
static void
polkit_backend_local_init (PolkitBackendLocal *backend)
{
PolkitBackendLocalPrivate *priv;
PolkitBackendLocalPrivate *priv;
priv = POLKIT_BACKEND_LOCAL_GET_PRIVATE (backend);
priv = POLKIT_BACKEND_LOCAL_GET_PRIVATE (backend);
}
PolkitBackendLocal *
polkit_backend_local_new (void)
{
PolkitBackendLocal *backend;
PolkitBackendLocal *backend;
backend = POLKIT_BACKEND_LOCAL (g_object_new (POLKIT_TYPE_BACKEND_LOCAL,
NULL));
backend = POLKIT_BACKEND_LOCAL (g_object_new (POLKIT_TYPE_BACKEND_LOCAL,
NULL));
return backend;
return backend;
}
static void
......@@ -92,58 +90,61 @@ authority_iface_handle_say_hello (PolkitAuthority *instance,
const gchar *message,
EggDBusMethodInvocation *method_invocation)
{
gchar *result;
gchar *result;
result = g_strdup_printf ("You said '%s' to the AUTHORITY!", message);
result = g_strdup_printf ("You said '%s' to the AUTHORITY!", message);
polkit_authority_handle_say_hello_finish (method_invocation,
result);
polkit_authority_handle_say_hello_finish (method_invocation,
result);
g_free (result);
g_free (result);
}
static void
authority_iface_handle_enumerate_users (PolkitAuthority *instance,
EggDBusMethodInvocation *method_invocation)
{
struct passwd *passwd;
GList *list;
struct passwd *passwd;
GList *list;
list = NULL;
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;
}
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;
do
{
PolkitSubject *subject;
subject = polkit_subject_new_for_unix_user (passwd->pw_uid);
subject = polkit_subject_new_for_unix_user (passwd->pw_uid);
list = g_list_prepend (list, subject);
} while ((passwd = getpwent ()) != NULL);
endpwent ();
list = g_list_prepend (list, subject);
}
while ((passwd = getpwent ()) != NULL);
endpwent ();
list = g_list_reverse (list);
list = g_list_reverse (list);
polkit_authority_handle_enumerate_users_finish (method_invocation,
list);
polkit_authority_handle_enumerate_users_finish (method_invocation,
list);
out:
g_list_foreach (list, (GFunc) g_object_unref, NULL);
g_list_free (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;
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2008 Red Hat, Inc.
*
......@@ -44,25 +42,25 @@ typedef struct _PolkitBackendLocalClass PolkitBackendLocalClass;
struct _PolkitBackendLocal
{
GObject parent_instance;
GObject parent_instance;
};
struct _PolkitBackendLocalClass
{
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);
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_local_get_type (void) G_GNUC_CONST;
......
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
/*
* Copyright (C) 2008 Red Hat, Inc.
*
* Copyright (C) 2007 David Zeuthen <david@fubar.dk>
* 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.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 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.
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
* 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
......@@ -34,58 +29,60 @@
static PolkitAuthority *
get_authority_backend (void)
{
/* TODO: use extension points etc. */
return POLKIT_AUTHORITY (polkit_backend_local_new ());
/* TODO: use extension points etc. */
return POLKIT_AUTHORITY (polkit_backend_local_new ());
}
int
main (int argc, char **argv)
{
int ret;
guint rn_ret;