Commit 028e1aa5 authored by David Zeuthen's avatar David Zeuthen
Browse files

Use an object, not a GHashTable when passing details around

This is because bindable GObject APIs should never return or accept a
GHashTable, see http://bugzilla.gnome.org/show_bug.cgi?id=581686#c6
for details.
parent 6bc9c8ff
......@@ -66,6 +66,7 @@
<title>Core API Reference</title>
<xi:include href="xml/polkitauthority.xml"/>
<xi:include href="xml/polkitauthorizationresult.xml"/>
<xi:include href="xml/polkitdetails.xml"/>
<xi:include href="xml/polkiterror.xml"/>
<xi:include href="xml/polkitactiondescription.xml"/>
<xi:include href="xml/polkitauthoritymanager.xml"/>
......
......@@ -269,3 +269,20 @@ polkit_error_quark
polkit_error_get_type
</SECTION>
<SECTION>
<FILE>polkitdetails</FILE>
PolkitDetails
polkit_details_new
polkit_details_lookup
polkit_details_insert
polkit_details_get_keys
<SUBSECTION Standard>
PolkitDetailsClass
POLKIT_DETAILS
POLKIT_IS_DETAILS
POLKIT_TYPE_DETAILS
polkit_details_get_type
POLKIT_DETAILS_CLASS
POLKIT_IS_DETAILS_CLASS
POLKIT_DETAILS_GET_CLASS
</SECTION>
......@@ -3,6 +3,7 @@ polkit_authority_manager_get_type
polkit_authorization_get_type
polkit_action_description_get_type
polkit_details_get_type
polkit_check_authorization_flags_get_type
polkit_implicit_authorization_get_type
......
......@@ -45,6 +45,7 @@ libpolkit_gobject_1include_HEADERS = \
polkitprivate.h \
polkittypes.h \
polkitactiondescription.h \
polkitdetails.h \
polkitauthority.h \
polkitauthoritymanager.h \
polkiterror.h \
......@@ -63,9 +64,10 @@ libpolkit_gobject_1include_HEADERS = \
libpolkit_gobject_1_la_SOURCES = \
$(BUILT_SOURCES) \
$(polkit_built_sources) \
$(polkit_built_sources) \
polkit.h \
polkitactiondescription.c polkitactiondescription.h \
polkitdetails.c polkitdetails.h \
polkitauthority.c polkitauthority.h \
polkitauthoritymanager.c polkitauthoritymanager.h \
polkiterror.c polkiterror.h \
......
......@@ -39,6 +39,7 @@
#include <polkit/polkitauthority.h>
#include <polkit/polkitauthoritymanager.h>
#include <polkit/polkitauthorization.h>
#include <polkit/polkitdetails.h>
#undef _POLKIT_INSIDE_POLKIT_H
......
......@@ -330,7 +330,7 @@ static guint
polkit_authority_check_authorization_async (PolkitAuthority *authority,
PolkitSubject *subject,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitCheckAuthorizationFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
......@@ -360,13 +360,18 @@ polkit_authority_check_authorization_async (PolkitAuthority *autho
G_TYPE_STRING, NULL);
if (details != NULL)
{
GHashTable *hash;
GHashTableIter iter;
const gchar *key;
const gchar *value;
g_hash_table_iter_init (&iter, details);
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value))
egg_dbus_hash_map_insert (real_details, key, value);
hash = polkit_details_get_hash (details);
if (hash != NULL)
{
g_hash_table_iter_init (&iter, hash);
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value))
egg_dbus_hash_map_insert (real_details, key, value);
}
}
call_id = _polkit_authority_check_authorization (authority->real,
......@@ -407,7 +412,7 @@ void
polkit_authority_check_authorization (PolkitAuthority *authority,
PolkitSubject *subject,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitCheckAuthorizationFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
......@@ -535,7 +540,7 @@ PolkitAuthorizationResult *
polkit_authority_check_authorization_sync (PolkitAuthority *authority,
PolkitSubject *subject,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitCheckAuthorizationFlags flags,
GCancellable *cancellable,
GError **error)
......
......@@ -65,7 +65,7 @@ GList *polkit_authority_enumerate_groups_sync (PolkitAuthori
PolkitAuthorizationResult *polkit_authority_check_authorization_sync (PolkitAuthority *authority,
PolkitSubject *subject,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitCheckAuthorizationFlags flags,
GCancellable *cancellable,
GError **error);
......@@ -103,7 +103,7 @@ GList * polkit_authority_enumerate_actions_finish (PolkitAuth
void polkit_authority_check_authorization (PolkitAuthority *authority,
PolkitSubject *subject,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitCheckAuthorizationFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
......
......@@ -40,6 +40,8 @@ struct _PolkitAuthorizationResult
GObject parent_instance;
_PolkitAuthorizationResult *real;
PolkitDetails *details;
};
struct _PolkitAuthorizationResultClass
......@@ -62,6 +64,8 @@ polkit_authorization_result_finalize (GObject *object)
authorization_result = POLKIT_AUTHORIZATION_RESULT (object);
g_object_unref (authorization_result->real);
if (authorization_result->details != NULL)
g_object_unref (authorization_result->details);
if (G_OBJECT_CLASS (polkit_authorization_result_parent_class)->finalize != NULL)
G_OBJECT_CLASS (polkit_authorization_result_parent_class)->finalize (object);
......@@ -108,7 +112,7 @@ polkit_authorization_result_get_real (PolkitAuthorizationResult *authorization_
PolkitAuthorizationResult *
polkit_authorization_result_new (gboolean is_authorized,
gboolean is_challenge,
GHashTable *details)
PolkitDetails *details)
{
PolkitAuthorizationResult *authorization_result;
_PolkitAuthorizationResult *real;
......@@ -117,13 +121,18 @@ polkit_authorization_result_new (gboolean is_authorized,
real_details = egg_dbus_hash_map_new (G_TYPE_STRING, g_free, G_TYPE_STRING, g_free);
if (details != NULL)
{
GHashTable *hash;
GHashTableIter iter;
gpointer key, value;
g_hash_table_iter_init (&iter, details);
while (g_hash_table_iter_next (&iter, &key, &value))
hash = polkit_details_get_hash (details);
if (hash != NULL)
{
egg_dbus_hash_map_insert (real_details, g_strdup (key), g_strdup (value));
g_hash_table_iter_init (&iter, hash);
while (g_hash_table_iter_next (&iter, &key, &value))
{
egg_dbus_hash_map_insert (real_details, g_strdup (key), g_strdup (value));
}
}
}
......@@ -173,14 +182,18 @@ polkit_authorization_result_get_is_challenge (PolkitAuthorizationResult *result)
*
* Returns:
**/
GHashTable *
PolkitDetails *
polkit_authorization_result_get_details (PolkitAuthorizationResult *result)
{
EggDBusHashMap *real_details;
if (result->details != NULL)
goto out;
real_details = _polkit_authorization_result_get_details (result->real);
if (real_details != NULL)
return real_details->data;
else
return NULL;
result->details = result->details = polkit_details_new_for_hash (real_details->data);
out:
return result->details;
}
......@@ -46,10 +46,10 @@ typedef struct _PolkitAuthorizationResultClass PolkitAuthorizationResultClass;
GType polkit_authorization_result_get_type (void) G_GNUC_CONST;
PolkitAuthorizationResult *polkit_authorization_result_new (gboolean is_authorized,
gboolean is_challenge,
GHashTable *details);
PolkitDetails *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);
PolkitDetails *polkit_authorization_result_get_details (PolkitAuthorizationResult *result);
/* ---------------------------------------------------------------------------------------------------- */
......
......@@ -50,4 +50,8 @@ _PolkitAuthorization *polkit_authorization_get_real (PolkitAuthorization *a
PolkitAuthorizationResult *polkit_authorization_result_new_for_real (_PolkitAuthorizationResult *real);
_PolkitAuthorizationResult *polkit_authorization_result_get_real (PolkitAuthorizationResult *authorization_result);
PolkitDetails *polkit_details_new_for_hash (GHashTable *hash);
GHashTable *polkit_details_get_hash (PolkitDetails *details);
#endif /* __POLKIT_PRIVATE_H */
......@@ -58,4 +58,7 @@ typedef struct _PolkitAuthorization PolkitAuthorization;
struct _PolkitAuthorizationResult;
typedef struct _PolkitAuthorizationResult PolkitAuthorizationResult;
struct _PolkitDetails;
typedef struct _PolkitDetails PolkitDetails;
#endif /* __POLKIT_TYPES_H */
......@@ -371,6 +371,7 @@ handle_begin_authentication (_PolkitAuthenticationAgent *instance,
GList *list;
guint n;
GCancellable *cancellable;
PolkitDetails *_details;
list = NULL;
for (n = 0; n < identities->size; n++)
......@@ -391,11 +392,13 @@ handle_begin_authentication (_PolkitAuthenticationAgent *instance,
g_hash_table_insert (server->cookie_to_pending_auth, (gpointer) cookie, data);
_details = polkit_details_new_for_hash (details->data);
polkit_agent_listener_initiate_authentication (server->listener,
action_id,
message,
icon_name,
details->data,
_details,
cookie,
list,
data->cancellable,
......@@ -403,6 +406,7 @@ handle_begin_authentication (_PolkitAuthenticationAgent *instance,
data);
g_list_free (list);
g_object_unref (_details);
}
static void
......@@ -456,7 +460,7 @@ polkit_agent_listener_class_init (PolkitAgentListenerClass *klass)
* @action_id: The action to authenticate for.
* @message: The message to present to the user.
* @icon_name: A themed icon name representing the action or %NULL.
* @details: A set of key/value string pairs describing the action.
* @details: Details describing the action.
* @cookie: The cookie for the authentication request.
* @identities: A list of #PolkitIdentity objects that the user can choose to authenticate as.
* @cancellable: A #GCancellable.
......@@ -479,7 +483,7 @@ polkit_agent_listener_initiate_authentication (PolkitAgentListener *listener,
const gchar *action_id,
const gchar *message,
const gchar *icon_name,
GHashTable *details,
PolkitDetails *details,
const gchar *cookie,
GList *identities,
GCancellable *cancellable,
......
......@@ -69,7 +69,7 @@ struct _PolkitAgentListenerClass
const gchar *action_id,
const gchar *message,
const gchar *icon_name,
GHashTable *details,
PolkitDetails *details,
const gchar *cookie,
GList *identities,
GCancellable *cancellable,
......@@ -97,7 +97,7 @@ void polkit_agent_listener_initiate_authentication (PolkitAgentList
const gchar *action_id,
const gchar *message,
const gchar *icon_name,
GHashTable *details,
PolkitDetails *details,
const gchar *cookie,
GList *identities,
GCancellable *cancellable,
......
......@@ -49,10 +49,10 @@
* e.g. messages that include more information than just the action
* name.
*
* Code implementing this interface <emphasis>cannot</emphasis>
* block or do any IO when methods are invoked. If information is
* needed to format the message or details, prepare it in advance and
* pass it as part of the @details hash table when doing the
* Code implementing this interface <emphasis>cannot</emphasis> block
* or do any IO when methods are invoked. If information is needed to
* format the message or details, prepare it in advance and pass it as
* part of the @details object when doing the
* polkit_authority_check_authorization() call. Then the code in this
* interface can use that information to return localized data.
*
......@@ -112,7 +112,7 @@ polkit_backend_action_lookup_get_type (void)
gchar *
polkit_backend_action_lookup_get_message (PolkitBackendActionLookup *lookup,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitActionDescription *action_description)
{
PolkitBackendActionLookupIface *iface = POLKIT_BACKEND_ACTION_LOOKUP_GET_IFACE (lookup);
......@@ -138,7 +138,7 @@ polkit_backend_action_lookup_get_message (PolkitBackendActionLookup *lookup,
gchar *
polkit_backend_action_lookup_get_icon_name (PolkitBackendActionLookup *lookup,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitActionDescription *action_description)
{
PolkitBackendActionLookupIface *iface = POLKIT_BACKEND_ACTION_LOOKUP_GET_IFACE (lookup);
......@@ -159,12 +159,12 @@ polkit_backend_action_lookup_get_icon_name (PolkitBackendActionLookup *lookup,
* Computes localized details to show in an authentication dialog for
* @action_id and @details.
*
* Returns: A #GHashTable with localized details or %NULL. Caller must free the result.
* Returns: A #PolkitDetails object with localized details or %NULL. Caller must free the result.
**/
GHashTable *
PolkitDetails *
polkit_backend_action_lookup_get_details (PolkitBackendActionLookup *lookup,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitActionDescription *action_description)
{
PolkitBackendActionLookupIface *iface = POLKIT_BACKEND_ACTION_LOOKUP_GET_IFACE (lookup);
......
......@@ -70,35 +70,35 @@ struct _PolkitBackendActionLookupIface
/*< public >*/
/* VTable */
gchar * (*get_message) (PolkitBackendActionLookup *lookup,
const gchar *action_id,
GHashTable *details,
PolkitActionDescription *action_description);
gchar * (*get_message) (PolkitBackendActionLookup *lookup,
const gchar *action_id,
PolkitDetails *details,
PolkitActionDescription *action_description);
gchar * (*get_icon_name) (PolkitBackendActionLookup *lookup,
const gchar *action_id,
GHashTable *details,
PolkitActionDescription *action_description);
gchar * (*get_icon_name) (PolkitBackendActionLookup *lookup,
const gchar *action_id,
PolkitDetails *details,
PolkitActionDescription *action_description);
GHashTable * (*get_details) (PolkitBackendActionLookup *lookup,
const gchar *action_id,
GHashTable *details,
PolkitActionDescription *action_description);
PolkitDetails * (*get_details) (PolkitBackendActionLookup *lookup,
const gchar *action_id,
PolkitDetails *details,
PolkitActionDescription *action_description);
};
GType polkit_backend_action_lookup_get_type (void) G_GNUC_CONST;
gchar *polkit_backend_action_lookup_get_message (PolkitBackendActionLookup *lookup,
const gchar *action_id,
GHashTable *details,
PolkitActionDescription *action_description);
gchar *polkit_backend_action_lookup_get_icon_name (PolkitBackendActionLookup *lookup,
const gchar *action_id,
GHashTable *details,
PolkitActionDescription *action_description);
GHashTable *polkit_backend_action_lookup_get_details (PolkitBackendActionLookup *lookup,
const gchar *action_id,
GHashTable *details,
PolkitActionDescription *action_description);
GType polkit_backend_action_lookup_get_type (void) G_GNUC_CONST;
gchar *polkit_backend_action_lookup_get_message (PolkitBackendActionLookup *lookup,
const gchar *action_id,
PolkitDetails *details,
PolkitActionDescription *action_description);
gchar *polkit_backend_action_lookup_get_icon_name (PolkitBackendActionLookup *lookup,
const gchar *action_id,
PolkitDetails *details,
PolkitActionDescription *action_description);
PolkitDetails *polkit_backend_action_lookup_get_details (PolkitBackendActionLookup *lookup,
const gchar *action_id,
PolkitDetails *details,
PolkitActionDescription *action_description);
G_END_DECLS
......
......@@ -222,7 +222,7 @@ polkit_backend_authority_check_authorization (PolkitBackendAuthority *aut
PolkitSubject *caller,
PolkitSubject *subject,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitCheckAuthorizationFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
......@@ -830,14 +830,14 @@ authority_handle_check_authorization (_PolkitAuthority *instance,
PolkitSubject *subject;
PolkitSubject *caller;
GCancellable *cancellable;
GHashTable *details;
PolkitDetails *details;
caller_name = egg_dbus_method_invocation_get_caller (method_invocation);
caller = polkit_system_bus_name_new (caller_name);
subject = polkit_subject_new_for_real (real_subject);
details = real_details->data;
details = polkit_details_new_for_hash (real_details->data);
g_object_set_data_full (G_OBJECT (method_invocation), "caller", caller, (GDestroyNotify) g_object_unref);
g_object_set_data_full (G_OBJECT (method_invocation), "subject", subject, (GDestroyNotify) g_object_unref);
......@@ -881,7 +881,7 @@ authority_handle_check_authorization (_PolkitAuthority *instance,
check_auth_cb,
method_invocation);
out:
;
g_object_unref (details);
}
static void
......
......@@ -123,7 +123,7 @@ struct _PolkitBackendAuthorityClass
PolkitSubject *caller,
PolkitSubject *subject,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitCheckAuthorizationFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
......@@ -221,7 +221,7 @@ void polkit_backend_authority_check_authorization (PolkitBackendAuthor
PolkitSubject *caller,
PolkitSubject *subject,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitCheckAuthorizationFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
......
......@@ -94,7 +94,7 @@ static void authentication_agent_initiate_challenge (Authenticati
PolkitIdentity *user_of_subject,
PolkitBackendLocalAuthority *authority,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitSubject *caller,
PolkitImplicitAuthorization implicit_authorization,
GCancellable *cancellable,
......@@ -167,7 +167,7 @@ static void polkit_backend_local_authority_check_authorization (PolkitBackendAut
PolkitSubject *caller,
PolkitSubject *subject,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitCheckAuthorizationFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
......@@ -540,7 +540,7 @@ polkit_backend_local_authority_check_authorization (PolkitBackendAuthority
PolkitSubject *caller,
PolkitSubject *subject,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitCheckAuthorizationFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
......@@ -1546,7 +1546,7 @@ get_localized_data_for_challenge (PolkitBackendLocalAuthority *authority,
PolkitSubject *subject,
PolkitIdentity *user_of_subject,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
const gchar *locale,
gchar **out_localized_message,
gchar **out_localized_icon_name,
......@@ -1554,14 +1554,11 @@ get_localized_data_for_challenge (PolkitBackendLocalAuthority *authority,
{
PolkitBackendLocalAuthorityPrivate *priv;
PolkitActionDescription *action_desc;
GHashTableIter iter;
const gchar *key;
const gchar *value;
GList *action_lookup_list;
GList *l;
gchar *message;
gchar *icon_name;
GHashTable *localized_details;
PolkitDetails *localized_details;
priv = POLKIT_BACKEND_LOCAL_AUTHORITY_GET_PRIVATE (authority);
......@@ -1639,10 +1636,19 @@ get_localized_data_for_challenge (PolkitBackendLocalAuthority *authority,
if (localized_details != NULL)
{
g_hash_table_iter_init (&iter, localized_details);
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value))
GHashTable *hash;
GHashTableIter iter;
const gchar *key;
const gchar *value;
hash = polkit_details_get_hash (localized_details);
if (hash != NULL)
{
egg_dbus_hash_map_insert (*out_localized_details, key, value);
g_hash_table_iter_init (&iter, hash);
while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &value))
{
egg_dbus_hash_map_insert (*out_localized_details, key, value);
}
}
}
......@@ -1663,7 +1669,7 @@ authentication_agent_initiate_challenge (AuthenticationAgent *agent,
PolkitIdentity *user_of_subject,
PolkitBackendLocalAuthority *authority,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitSubject *caller,
PolkitImplicitAuthorization implicit_authorization,
GCancellable *cancellable,
......
......@@ -84,7 +84,7 @@ polkit_exec_action_lookup_class_init (PolkitExecActionLookupClass *klass)
static gchar *
polkit_exec_action_lookup_get_message (PolkitBackendActionLookup *lookup,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitActionDescription *action_description)
{
gchar *ret;
......@@ -96,11 +96,11 @@ polkit_exec_action_lookup_get_message (PolkitBackendActionLookup *lookup,
if (g_strcmp0 (action_id, "org.freedesktop.policykit.exec") != 0)
goto out;
s = g_hash_table_lookup (details, "program");
s = polkit_details_lookup (details, "program");
if (s == NULL)
goto out;
s2 = g_hash_table_lookup (details, "uid");
s2 = polkit_details_lookup (details, "uid");
if (s2 == NULL)
goto out;
......@@ -122,7 +122,7 @@ polkit_exec_action_lookup_get_message (PolkitBackendActionLookup *lookup,
static gchar *
polkit_exec_action_lookup_get_icon_name (PolkitBackendActionLookup *lookup,
const gchar *action_id,
GHashTable *details,
PolkitDetails *details,
PolkitActionDescription *action_description)
{
gchar *ret;
......@@ -134,15 +134,15 @@ polkit_exec_action_lookup_get_icon_name (PolkitBackendActionLookup *lookup,
return ret;
}
static GHashTable *
static PolkitDetails *
polkit_exec_action_lookup_get_details (PolkitBackendActionLookup *lookup,
const gchar *action_id,
GHashTable *details,
PolkitActionDescription *action_desc)
const gchar *action_id,
PolkitDetails *details,
PolkitActionDescription *action_desc)
{
const gchar *s;
const gchar *s2;
GHashTable *ret;
PolkitDetails *ret;
ret = NULL;