1 /* GDBus - GLib D-Bus Library
3 * Copyright (C) 2008-2010 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: David Zeuthen <davidz@redhat.com>
25 #include "gdbusauthmechanism.h"
26 #include "gcredentials.h"
27 #include "gdbuserror.h"
28 #include "gioenumtypes.h"
29 #include "giostream.h"
34 /* ---------------------------------------------------------------------------------------------------- */
36 struct _GDBusAuthMechanismPrivate
39 GCredentials *credentials;
49 G_DEFINE_ABSTRACT_TYPE (GDBusAuthMechanism, _g_dbus_auth_mechanism, G_TYPE_OBJECT);
51 /* ---------------------------------------------------------------------------------------------------- */
54 _g_dbus_auth_mechanism_finalize (GObject *object)
56 GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object);
58 if (mechanism->priv->stream != NULL)
59 g_object_unref (mechanism->priv->stream);
60 if (mechanism->priv->credentials != NULL)
61 g_object_unref (mechanism->priv->credentials);
63 if (G_OBJECT_CLASS (_g_dbus_auth_mechanism_parent_class)->finalize != NULL)
64 G_OBJECT_CLASS (_g_dbus_auth_mechanism_parent_class)->finalize (object);
68 _g_dbus_auth_mechanism_get_property (GObject *object,
73 GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object);
78 g_value_set_object (value, mechanism->priv->stream);
81 case PROP_CREDENTIALS:
82 g_value_set_object (value, mechanism->priv->credentials);
86 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
92 _g_dbus_auth_mechanism_set_property (GObject *object,
97 GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object);
102 mechanism->priv->stream = g_value_dup_object (value);
105 case PROP_CREDENTIALS:
106 mechanism->priv->credentials = g_value_dup_object (value);
110 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
116 _g_dbus_auth_mechanism_class_init (GDBusAuthMechanismClass *klass)
118 GObjectClass *gobject_class;
120 g_type_class_add_private (klass, sizeof (GDBusAuthMechanismPrivate));
122 gobject_class = G_OBJECT_CLASS (klass);
123 gobject_class->get_property = _g_dbus_auth_mechanism_get_property;
124 gobject_class->set_property = _g_dbus_auth_mechanism_set_property;
125 gobject_class->finalize = _g_dbus_auth_mechanism_finalize;
127 g_object_class_install_property (gobject_class,
129 g_param_spec_object ("stream",
131 _("The underlying GIOStream used for I/O"),
135 G_PARAM_CONSTRUCT_ONLY |
136 G_PARAM_STATIC_NAME |
137 G_PARAM_STATIC_BLURB |
138 G_PARAM_STATIC_NICK));
141 * GDBusAuthMechanism:credentials:
143 * If authenticating as a server, this property contains the
144 * received credentials, if any.
146 * If authenticating as a client, the property contains the
147 * credentials that were sent, if any.
149 g_object_class_install_property (gobject_class,
151 g_param_spec_object ("credentials",
153 _("The credentials of the remote peer"),
157 G_PARAM_CONSTRUCT_ONLY |
158 G_PARAM_STATIC_NAME |
159 G_PARAM_STATIC_BLURB |
160 G_PARAM_STATIC_NICK));
164 _g_dbus_auth_mechanism_init (GDBusAuthMechanism *mechanism)
166 /* not used for now */
167 mechanism->priv = G_TYPE_INSTANCE_GET_PRIVATE (mechanism,
168 G_TYPE_DBUS_AUTH_MECHANISM,
169 GDBusAuthMechanismPrivate);
172 /* ---------------------------------------------------------------------------------------------------- */
175 _g_dbus_auth_mechanism_get_stream (GDBusAuthMechanism *mechanism)
177 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
178 return mechanism->priv->stream;
182 _g_dbus_auth_mechanism_get_credentials (GDBusAuthMechanism *mechanism)
184 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
185 return mechanism->priv->credentials;
188 /* ---------------------------------------------------------------------------------------------------- */
191 _g_dbus_auth_mechanism_get_name (GType mechanism_type)
194 GDBusAuthMechanismClass *klass;
196 g_return_val_if_fail (g_type_is_a (mechanism_type, G_TYPE_DBUS_AUTH_MECHANISM), NULL);
198 klass = g_type_class_ref (mechanism_type);
199 g_assert (klass != NULL);
200 name = klass->get_name ();
201 //g_type_class_unref (klass);
207 _g_dbus_auth_mechanism_get_priority (GType mechanism_type)
210 GDBusAuthMechanismClass *klass;
212 g_return_val_if_fail (g_type_is_a (mechanism_type, G_TYPE_DBUS_AUTH_MECHANISM), 0);
214 klass = g_type_class_ref (mechanism_type);
215 g_assert (klass != NULL);
216 priority = klass->get_priority ();
217 //g_type_class_unref (klass);
222 /* ---------------------------------------------------------------------------------------------------- */
225 _g_dbus_auth_mechanism_is_supported (GDBusAuthMechanism *mechanism)
227 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), FALSE);
228 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->is_supported (mechanism);
232 _g_dbus_auth_mechanism_encode_data (GDBusAuthMechanism *mechanism,
237 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
238 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->encode_data (mechanism, data, data_len, out_data_len);
243 _g_dbus_auth_mechanism_decode_data (GDBusAuthMechanism *mechanism,
248 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
249 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->decode_data (mechanism, data, data_len, out_data_len);
252 /* ---------------------------------------------------------------------------------------------------- */
254 GDBusAuthMechanismState
255 _g_dbus_auth_mechanism_server_get_state (GDBusAuthMechanism *mechanism)
257 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), G_DBUS_AUTH_MECHANISM_STATE_INVALID);
258 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_get_state (mechanism);
262 _g_dbus_auth_mechanism_server_initiate (GDBusAuthMechanism *mechanism,
263 const gchar *initial_response,
264 gsize initial_response_len)
266 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
267 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_initiate (mechanism, initial_response, initial_response_len);
271 _g_dbus_auth_mechanism_server_data_receive (GDBusAuthMechanism *mechanism,
275 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
276 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_data_receive (mechanism, data, data_len);
280 _g_dbus_auth_mechanism_server_data_send (GDBusAuthMechanism *mechanism,
283 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
284 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_data_send (mechanism, out_data_len);
288 _g_dbus_auth_mechanism_server_get_reject_reason (GDBusAuthMechanism *mechanism)
290 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
291 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_get_reject_reason (mechanism);
295 _g_dbus_auth_mechanism_server_shutdown (GDBusAuthMechanism *mechanism)
297 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
298 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_shutdown (mechanism);
301 /* ---------------------------------------------------------------------------------------------------- */
303 GDBusAuthMechanismState
304 _g_dbus_auth_mechanism_client_get_state (GDBusAuthMechanism *mechanism)
306 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), G_DBUS_AUTH_MECHANISM_STATE_INVALID);
307 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_get_state (mechanism);
311 _g_dbus_auth_mechanism_client_initiate (GDBusAuthMechanism *mechanism,
312 gsize *out_initial_response_len)
314 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
315 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_initiate (mechanism,
316 out_initial_response_len);
320 _g_dbus_auth_mechanism_client_data_receive (GDBusAuthMechanism *mechanism,
324 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
325 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_data_receive (mechanism, data, data_len);
329 _g_dbus_auth_mechanism_client_data_send (GDBusAuthMechanism *mechanism,
332 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
333 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_data_send (mechanism, out_data_len);
337 _g_dbus_auth_mechanism_client_shutdown (GDBusAuthMechanism *mechanism)
339 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
340 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_shutdown (mechanism);
343 /* ---------------------------------------------------------------------------------------------------- */
345 #define __G_DBUS_AUTH_MECHANISM_C__
346 #include "gioaliasdef.c"