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

Change the PolkitAuthorizationResult enumeration into an object

parent 86008e61
......@@ -109,18 +109,20 @@
<!-- ---------------------------------------------------------------------------------------------------- -->
<!-- An enumeration for results when checking for an authorization -->
<annotation name="org.gtk.EggDBus.DeclareEnum" value="AuthorizationResult">
<annotation name="org.gtk.EggDBus.DocString.Summary" value="Possible results for checking authorizations"/>
<annotation name="org.gtk.EggDBus.DocString" value="Possible results that the org.freedesktop.PolicyKit1.Authority.CheckAuthorization() method can return."/>
<annotation name="org.gtk.EggDBus.DeclareStruct" value="AuthorizationResult">
<annotation name="org.gtk.EggDBus.DocString.Summary" value="Authorization Results"/>
<annotation name="org.gtk.EggDBus.DocString" value="Describes the result of calling org.freedesktop.PolicyKit1.Authority.CheckAuthorization()."/>
<annotation name="org.gtk.EggDBus.Enum.Member" value="NotAuthorized">
<annotation name="org.gtk.EggDBus.DocString" value="The given #Subject is not authorized for the specified action."/>
<annotation name="org.gtk.EggDBus.Struct.Member" value="Boolean:is_authorized">
<annotation name="org.gtk.EggDBus.DocString" value="#TRUE if the given #Subject is authorized for the given action."/>
</annotation>
<annotation name="org.gtk.EggDBus.Enum.Member" value="Authorized">
<annotation name="org.gtk.EggDBus.DocString" value="The given #Subject is authorized for the specified action."/>
<annotation name="org.gtk.EggDBus.Struct.Member" value="Boolean:is_challenge">
<annotation name="org.gtk.EggDBus.DocString" value="#TRUE if the given #Subject could be authorized if more information was provided, and %CheckAuthorizationFlags.AllowUserInteraction wasn't passed."/>
</annotation>
<annotation name="org.gtk.EggDBus.Enum.Member" value="Challenge">
<annotation name="org.gtk.EggDBus.DocString" value="The given #Subject is authorized if more information is provided."/>
<annotation name="org.gtk.EggDBus.Struct.Member" value="Dict<String,String>:details">
<annotation name="org.gtk.EggDBus.DocString" value="Details for the result or empty if not authorized."/>
</annotation>
</annotation>
......@@ -226,9 +228,9 @@
<annotation name="org.gtk.EggDBus.DocString" value="A unique id used to cancel the the authentication check via org.freedesktop.PolicyKit1.Authority.CancelCheckAuthorization() or the empty string if cancellation is not needed."/>
</arg>
<arg name="result" direction="out" type="u">
<arg name="result" direction="out" type="(bba{ss})">
<annotation name="org.gtk.EggDBus.Type" value="AuthorizationResult"/>
<annotation name="org.gtk.EggDBus.DocString" value="A value from the #AuthorizationResult enumeration."/>
<annotation name="org.gtk.EggDBus.DocString" value="An #AuthorizationResult structure."/>
</arg>
</method>
......
......@@ -65,6 +65,7 @@
<reference id="ref-api">
<title>Core API Reference</title>
<xi:include href="xml/polkitauthority.xml"/>
<xi:include href="xml/polkitauthorizationresult.xml"/>
<xi:include href="xml/polkiterror.xml"/>
<xi:include href="xml/polkitactiondescription.xml"/>
<xi:include href="xml/polkitauthoritymanager.xml"/>
......
......@@ -50,7 +50,6 @@ POLKIT_AUTHORITY_MANAGER_GET_CLASS
<FILE>polkitauthority</FILE>
PolkitAuthority
PolkitCheckAuthorizationFlags
PolkitAuthorizationResult
polkit_authority_get
polkit_authority_enumerate_actions_sync
polkit_authority_check_authorization_sync
......@@ -78,6 +77,24 @@ POLKIT_IS_AUTHORITY_CLASS
POLKIT_AUTHORITY_GET_CLASS
</SECTION>
<SECTION>
<FILE>polkitauthorizationresult</FILE>
PolkitAuthorizationResult
polkit_authorization_result_new
polkit_authorization_result_get_is_authorized
polkit_authorization_result_get_is_challenge
polkit_authorization_result_get_details
<SUBSECTION Standard>
PolkitAuthorizationResultClass
POLKIT_AUTHORIZATION_RESULT
POLKIT_IS_AUTHORIZATION_RESULT
POLKIT_TYPE_AUTHORIZATION_RESULT
polkit_authorization_result_get_type
POLKIT_AUTHORIZATION_RESULT_CLASS
POLKIT_IS_AUTHORIZATION_RESULT_CLASS
POLKIT_AUTHORIZATION_RESULT_GET_CLASS
</SECTION>
<SECTION>
<FILE>polkitsystembusname</FILE>
PolkitSystemBusName
......@@ -252,11 +269,3 @@ polkit_error_quark
polkit_error_get_type
</SECTION>
<SECTION>
<FILE>polkitauthorizationresult</FILE>
POLKIT_TYPE_AUTHORIZATION_RESULT
PolkitAuthorizationResult
<SUBSECTION Standard>
polkit_authorization_result_get_type
</SECTION>
......@@ -448,14 +448,15 @@ authorization_check_cancelled_cb (GObject *source_object,
*
* Finishes checking if a subject is authorized for an action.
*
* Returns: A #PolkitAuthorizationResult.
* Returns: A #PolkitAuthorizationResult or %NULL if @error is set. Free with g_object_unref().
**/
PolkitAuthorizationResult
PolkitAuthorizationResult *
polkit_authority_check_authorization_finish (PolkitAuthority *authority,
GAsyncResult *res,
GError **error)
{
_PolkitAuthorizationResult result;
PolkitAuthorizationResult *result;
_PolkitAuthorizationResult *real_result;
GSimpleAsyncResult *simple;
GAsyncResult *real_res;
GError *local_error;
......@@ -465,11 +466,11 @@ polkit_authority_check_authorization_finish (PolkitAuthority *authority
g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_authority_check_authorization_async);
result = _POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED;
result = NULL;
local_error = NULL;
_polkit_authority_check_authorization_finish (authority->real,
&result,
&real_result,
real_res,
&local_error);
......@@ -504,8 +505,14 @@ polkit_authority_check_authorization_finish (PolkitAuthority *authority
g_propagate_error (error, local_error);
}
}
g_object_unref (real_res);
if (real_result != NULL)
{
result = polkit_authorization_result_new_for_real (real_result);
g_object_unref (real_result);
}
return result;
}
......@@ -521,9 +528,9 @@ polkit_authority_check_authorization_finish (PolkitAuthority *authority
*
* Checks if @subject is authorized to perform the action represented by @action_id.
*
* Returns: A #PolkitAuthorizationResult.
* Returns: A #PolkitAuthorizationResult or %NULL if @error is set. Free with g_object_unref().
*/
PolkitAuthorizationResult
PolkitAuthorizationResult *
polkit_authority_check_authorization_sync (PolkitAuthority *authority,
PolkitSubject *subject,
const gchar *action_id,
......@@ -534,7 +541,7 @@ polkit_authority_check_authorization_sync (PolkitAuthority *author
{
guint call_id;
GAsyncResult *res;
PolkitAuthorizationResult result;
PolkitAuthorizationResult *result;
call_id = polkit_authority_check_authorization_async (authority,
subject,
......
......@@ -62,7 +62,7 @@ GList *polkit_authority_enumerate_groups_sync (PolkitAuthori
GCancellable *cancellable,
GError **error);
PolkitAuthorizationResult polkit_authority_check_authorization_sync (PolkitAuthority *authority,
PolkitAuthorizationResult *polkit_authority_check_authorization_sync (PolkitAuthority *authority,
PolkitSubject *subject,
const gchar *action_id,
GHashTable *details,
......@@ -109,7 +109,7 @@ void polkit_authority_check_authorization (PolkitAuthority
GAsyncReadyCallback callback,
gpointer user_data);
PolkitAuthorizationResult polkit_authority_check_authorization_finish (PolkitAuthority *authority,
PolkitAuthorizationResult *polkit_authority_check_authorization_finish (PolkitAuthority *authority,
GAsyncResult *res,
GError **error);
......
......@@ -26,18 +26,161 @@
#include "polkitauthorizationresult.h"
#include "polkitprivate.h"
/**
* SECTION:polkitauthorizationresult
* @title: PolkitAuthorizationResult
* @short_result: Authorization Results
* @short_description: Result for checking an authorization
* @stability: Stable
*
* Results of a check for an claim.
* This class represents the result you get when checking for an authorization.
*/
GType
polkit_authorization_result_get_type (void)
struct _PolkitAuthorizationResult
{
GObject parent_instance;
_PolkitAuthorizationResult *real;
};
struct _PolkitAuthorizationResultClass
{
GObjectClass parent_class;
};
G_DEFINE_TYPE (PolkitAuthorizationResult, polkit_authorization_result, G_TYPE_OBJECT);
static void
polkit_authorization_result_init (PolkitAuthorizationResult *authorization_result)
{
}
static void
polkit_authorization_result_finalize (GObject *object)
{
return _polkit_authorization_result_get_type ();
PolkitAuthorizationResult *authorization_result;
authorization_result = POLKIT_AUTHORIZATION_RESULT (object);
g_object_unref (authorization_result->real);
if (G_OBJECT_CLASS (polkit_authorization_result_parent_class)->finalize != NULL)
G_OBJECT_CLASS (polkit_authorization_result_parent_class)->finalize (object);
}
static void
polkit_authorization_result_class_init (PolkitAuthorizationResultClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->finalize = polkit_authorization_result_finalize;
}
PolkitAuthorizationResult *
polkit_authorization_result_new_for_real (_PolkitAuthorizationResult *real)
{
PolkitAuthorizationResult *authorization_result;
authorization_result = POLKIT_AUTHORIZATION_RESULT (g_object_new (POLKIT_TYPE_AUTHORIZATION_RESULT, NULL));
authorization_result->real = g_object_ref (real);
return authorization_result;
}
_PolkitAuthorizationResult *
polkit_authorization_result_get_real (PolkitAuthorizationResult *authorization_result)
{
return g_object_ref (authorization_result->real);
}
/* ---------------------------------------------------------------------------------------------------- */
/**
* polkit_authorization_result_new:
* @is_authorized:
* @is_challenge:
* @details:
*
*
*
* Returns:
**/
PolkitAuthorizationResult *
polkit_authorization_result_new (gboolean is_authorized,
gboolean is_challenge,
GHashTable *details)
{
PolkitAuthorizationResult *authorization_result;
_PolkitAuthorizationResult *real;
EggDBusHashMap *real_details;
real_details = egg_dbus_hash_map_new (G_TYPE_STRING, g_free, G_TYPE_STRING, g_free);
if (details != NULL)
{
GHashTableIter iter;
gpointer key, value;
g_hash_table_iter_init (&iter, details);
while (g_hash_table_iter_next (&iter, &key, &value))
{
egg_dbus_hash_map_insert (real_details, g_strdup (key), g_strdup (value));
}
}
real = _polkit_authorization_result_new (is_authorized, is_challenge, real_details);
g_object_unref (real_details);
authorization_result = polkit_authorization_result_new_for_real (real);
g_object_unref (real);
return authorization_result;
}
/**
* polkit_authorization_result_get_is_authorized:
* @result:
*
*
*
* Returns:
**/
gboolean
polkit_authorization_result_get_is_authorized (PolkitAuthorizationResult *result)
{
return _polkit_authorization_result_get_is_authorized (result->real);
}
/**
* polkit_authorization_result_get_is_challenge:
* @result:
*
*
*
* Returns:
**/
gboolean
polkit_authorization_result_get_is_challenge (PolkitAuthorizationResult *result)
{
return _polkit_authorization_result_get_is_challenge (result->real);
}
/**
* polkit_authorization_result_get_details:
* @result:
*
*
*
* Returns:
**/
GHashTable *
polkit_authorization_result_get_details (PolkitAuthorizationResult *result)
{
EggDBusHashMap *real_details;
real_details = _polkit_authorization_result_get_details (result->real);
if (real_details != NULL)
return real_details->data;
else
return NULL;
}
......@@ -27,27 +27,31 @@
#define __POLKIT_AUTHORIZATION_RESULT_H
#include <glib-object.h>
#include <polkit/polkittypes.h>
G_BEGIN_DECLS
GType polkit_authorization_result_get_type (void) G_GNUC_CONST;
#define POLKIT_TYPE_AUTHORIZATION_RESULT (polkit_authorization_result_get_type())
#define POLKIT_AUTHORIZATION_RESULT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_TYPE_AUTHORIZATION_RESULT, PolkitAuthorizationResult))
#define POLKIT_AUTHORIZATION_RESULT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), POLKIT_TYPE_AUTHORIZATION_RESULT, PolkitAuthorizationResultClass))
#define POLKIT_AUTHORIZATION_RESULT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_TYPE_AUTHORIZATION_RESULT, PolkitAuthorizationResultClass))
#define POLKIT_IS_AUTHORIZATION_RESULT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_TYPE_AUTHORIZATION_RESULT))
#define POLKIT_IS_AUTHORIZATION_RESULT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_TYPE_AUTHORIZATION_RESULT))
#define POLKIT_TYPE_AUTHORIZATION_RESULT (polkit_authorization_result_get_type ())
#if 0
typedef struct _PolkitAuthorizationResult PolkitAuthorizationResult;
#endif
typedef struct _PolkitAuthorizationResultClass PolkitAuthorizationResultClass;
/**
* PolkitAuthorizationResult:
* @POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED: The subject is not authorized for the specified action
* @POLKIT_AUTHORIZATION_RESULT_AUTHORIZED: The subject is authorized for the specified action
* @POLKIT_AUTHORIZATION_RESULT_CHALLENGE: The subject is authorized if more information is provided
*
* Result codes for checking whether a subject is authorized for an action.
*/
typedef enum
{
POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED = 0,
POLKIT_AUTHORIZATION_RESULT_AUTHORIZED = 1,
POLKIT_AUTHORIZATION_RESULT_CHALLENGE = 2,
} PolkitAuthorizationResult;
GType polkit_authorization_result_get_type (void) G_GNUC_CONST;
PolkitAuthorizationResult *polkit_authorization_result_new (gboolean is_authorized,
gboolean is_challenge,
GHashTable *details);
gboolean polkit_authorization_result_get_is_authorized (PolkitAuthorizationResult *result);
gboolean polkit_authorization_result_get_is_challenge (PolkitAuthorizationResult *result);
GHashTable *polkit_authorization_result_get_details (PolkitAuthorizationResult *result);
/* ---------------------------------------------------------------------------------------------------- */
G_END_DECLS
......
......@@ -25,6 +25,7 @@
#include "polkitimplicitauthorization.h"
#include "polkitactiondescription.h"
#include "polkitsubject.h"
#include "polkitauthorizationresult.h"
#include "_polkitbindings.h"
/* notes:
......@@ -46,4 +47,7 @@ _PolkitIdentity *polkit_identity_get_real (PolkitIdentity *identity);
PolkitAuthorization *polkit_authorization_new_for_real (_PolkitAuthorization *real);
_PolkitAuthorization *polkit_authorization_get_real (PolkitAuthorization *authorization);
PolkitAuthorizationResult *polkit_authorization_result_new_for_real (_PolkitAuthorizationResult *real);
_PolkitAuthorizationResult *polkit_authorization_result_get_real (PolkitAuthorizationResult *authorization_result);
#endif /* __POLKIT_PRIVATE_H */
......@@ -55,4 +55,7 @@ typedef struct _PolkitUnixGroup PolkitUnixGroup;
struct _PolkitAuthorization;
typedef struct _PolkitAuthorization PolkitAuthorization;
struct _PolkitAuthorizationResult;
typedef struct _PolkitAuthorizationResult PolkitAuthorizationResult;
#endif /* __POLKIT_TYPES_H */
......@@ -261,9 +261,9 @@ polkit_backend_authority_check_authorization (PolkitBackendAuthority *aut
*
* Finishes checking if a subject is authorized for an action.
*
* Returns: A #PolkitAuthorizationResult.
* Returns: A #PolkitAuthorizationResult or %NULL if @error is set. Free with g_object_unref().
**/
PolkitAuthorizationResult
PolkitAuthorizationResult *
polkit_backend_authority_check_authorization_finish (PolkitBackendAuthority *authority,
GAsyncResult *res,
GError **error)
......@@ -276,7 +276,7 @@ polkit_backend_authority_check_authorization_finish (PolkitBackendAuthority *au
{
g_warning ("check_authorization_finish is not implemented (it is not optional)");
g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
return POLKIT_AUTHORIZATION_RESULT_NOT_AUTHORIZED;
return NULL;
}
else
{
......@@ -786,7 +786,7 @@ check_auth_cb (GObject *source_object,
{
EggDBusMethodInvocation *method_invocation = EGG_DBUS_METHOD_INVOCATION (user_data);
const gchar *full_cancellation_id;
PolkitAuthorizationResult result;
PolkitAuthorizationResult *result;
GError *error;
error = NULL;
......@@ -809,7 +809,10 @@ check_auth_cb (GObject *source_object,
}
else
{
_polkit_authority_handle_check_authorization_finish (method_invocation, result);
_PolkitAuthorizationResult *real_result;
real_result = polkit_authorization_result_get_real (result);
_polkit_authority_handle_check_authorization_finish (method_invocation, real_result);
g_object_unref (result);
}
}
......
......@@ -129,9 +129,9 @@ struct _PolkitBackendAuthorityClass
GAsyncReadyCallback callback,
gpointer user_data);
PolkitAuthorizationResult (*check_authorization_finish) (PolkitBackendAuthority *authority,
GAsyncResult *res,
GError **error);
PolkitAuthorizationResult * (*check_authorization_finish) (PolkitBackendAuthority *authority,
GAsyncResult *res,
GError **error);
gboolean (*register_authentication_agent) (PolkitBackendAuthority *authority,
PolkitSubject *caller,
......@@ -227,9 +227,9 @@ void polkit_backend_authority_check_authorization (PolkitBackendAuthor
GAsyncReadyCallback callback,
gpointer user_data);
PolkitAuthorizationResult polkit_backend_authority_check_authorization_finish (PolkitBackendAuthority *authority,
GAsyncResult *res,
GError **error);
PolkitAuthorizationResult *polkit_backend_authority_check_authorization_finish (PolkitBackendAuthority *authority,
GAsyncResult *res,
GError **error);
GList *polkit_backend_authority_enumerate_authorizations (PolkitBackendAuthority *authority,
PolkitSubject *caller,
......
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