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"
33 /* ---------------------------------------------------------------------------------------------------- */
35 struct _GDBusAuthMechanismPrivate
38 GCredentials *credentials;
48 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GDBusAuthMechanism, _g_dbus_auth_mechanism, G_TYPE_OBJECT)
50 /* ---------------------------------------------------------------------------------------------------- */
53 _g_dbus_auth_mechanism_finalize (GObject *object)
55 GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object);
57 if (mechanism->priv->stream != NULL)
58 g_object_unref (mechanism->priv->stream);
59 if (mechanism->priv->credentials != NULL)
60 g_object_unref (mechanism->priv->credentials);
62 G_OBJECT_CLASS (_g_dbus_auth_mechanism_parent_class)->finalize (object);
66 _g_dbus_auth_mechanism_get_property (GObject *object,
71 GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object);
76 g_value_set_object (value, mechanism->priv->stream);
79 case PROP_CREDENTIALS:
80 g_value_set_object (value, mechanism->priv->credentials);
84 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
90 _g_dbus_auth_mechanism_set_property (GObject *object,
95 GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object);
100 mechanism->priv->stream = g_value_dup_object (value);
103 case PROP_CREDENTIALS:
104 mechanism->priv->credentials = g_value_dup_object (value);
108 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
114 _g_dbus_auth_mechanism_class_init (GDBusAuthMechanismClass *klass)
116 GObjectClass *gobject_class;
118 gobject_class = G_OBJECT_CLASS (klass);
119 gobject_class->get_property = _g_dbus_auth_mechanism_get_property;
120 gobject_class->set_property = _g_dbus_auth_mechanism_set_property;
121 gobject_class->finalize = _g_dbus_auth_mechanism_finalize;
123 g_object_class_install_property (gobject_class,
125 g_param_spec_object ("stream",
127 P_("The underlying GIOStream used for I/O"),
131 G_PARAM_CONSTRUCT_ONLY |
132 G_PARAM_STATIC_NAME |
133 G_PARAM_STATIC_BLURB |
134 G_PARAM_STATIC_NICK));
137 * GDBusAuthMechanism:credentials:
139 * If authenticating as a server, this property contains the
140 * received credentials, if any.
142 * If authenticating as a client, the property contains the
143 * credentials that were sent, if any.
145 g_object_class_install_property (gobject_class,
147 g_param_spec_object ("credentials",
149 P_("The credentials of the remote peer"),
153 G_PARAM_CONSTRUCT_ONLY |
154 G_PARAM_STATIC_NAME |
155 G_PARAM_STATIC_BLURB |
156 G_PARAM_STATIC_NICK));
160 _g_dbus_auth_mechanism_init (GDBusAuthMechanism *mechanism)
162 mechanism->priv = _g_dbus_auth_mechanism_get_instance_private (mechanism);
165 /* ---------------------------------------------------------------------------------------------------- */
168 _g_dbus_auth_mechanism_get_stream (GDBusAuthMechanism *mechanism)
170 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
171 return mechanism->priv->stream;
175 _g_dbus_auth_mechanism_get_credentials (GDBusAuthMechanism *mechanism)
177 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
178 return mechanism->priv->credentials;
181 /* ---------------------------------------------------------------------------------------------------- */
184 _g_dbus_auth_mechanism_get_name (GType mechanism_type)
187 GDBusAuthMechanismClass *klass;
189 g_return_val_if_fail (g_type_is_a (mechanism_type, G_TYPE_DBUS_AUTH_MECHANISM), NULL);
191 klass = g_type_class_ref (mechanism_type);
192 g_assert (klass != NULL);
193 name = klass->get_name ();
194 //g_type_class_unref (klass);
200 _g_dbus_auth_mechanism_get_priority (GType mechanism_type)
203 GDBusAuthMechanismClass *klass;
205 g_return_val_if_fail (g_type_is_a (mechanism_type, G_TYPE_DBUS_AUTH_MECHANISM), 0);
207 klass = g_type_class_ref (mechanism_type);
208 g_assert (klass != NULL);
209 priority = klass->get_priority ();
210 //g_type_class_unref (klass);
215 /* ---------------------------------------------------------------------------------------------------- */
218 _g_dbus_auth_mechanism_is_supported (GDBusAuthMechanism *mechanism)
220 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), FALSE);
221 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->is_supported (mechanism);
225 _g_dbus_auth_mechanism_encode_data (GDBusAuthMechanism *mechanism,
230 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
231 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->encode_data (mechanism, data, data_len, out_data_len);
236 _g_dbus_auth_mechanism_decode_data (GDBusAuthMechanism *mechanism,
241 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
242 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->decode_data (mechanism, data, data_len, out_data_len);
245 /* ---------------------------------------------------------------------------------------------------- */
247 GDBusAuthMechanismState
248 _g_dbus_auth_mechanism_server_get_state (GDBusAuthMechanism *mechanism)
250 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), G_DBUS_AUTH_MECHANISM_STATE_INVALID);
251 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_get_state (mechanism);
255 _g_dbus_auth_mechanism_server_initiate (GDBusAuthMechanism *mechanism,
256 const gchar *initial_response,
257 gsize initial_response_len)
259 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
260 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_initiate (mechanism, initial_response, initial_response_len);
264 _g_dbus_auth_mechanism_server_data_receive (GDBusAuthMechanism *mechanism,
268 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
269 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_data_receive (mechanism, data, data_len);
273 _g_dbus_auth_mechanism_server_data_send (GDBusAuthMechanism *mechanism,
276 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
277 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_data_send (mechanism, out_data_len);
281 _g_dbus_auth_mechanism_server_get_reject_reason (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_get_reject_reason (mechanism);
288 _g_dbus_auth_mechanism_server_shutdown (GDBusAuthMechanism *mechanism)
290 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
291 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_shutdown (mechanism);
294 /* ---------------------------------------------------------------------------------------------------- */
296 GDBusAuthMechanismState
297 _g_dbus_auth_mechanism_client_get_state (GDBusAuthMechanism *mechanism)
299 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), G_DBUS_AUTH_MECHANISM_STATE_INVALID);
300 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_get_state (mechanism);
304 _g_dbus_auth_mechanism_client_initiate (GDBusAuthMechanism *mechanism,
305 gsize *out_initial_response_len)
307 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
308 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_initiate (mechanism,
309 out_initial_response_len);
313 _g_dbus_auth_mechanism_client_data_receive (GDBusAuthMechanism *mechanism,
317 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
318 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_data_receive (mechanism, data, data_len);
322 _g_dbus_auth_mechanism_client_data_send (GDBusAuthMechanism *mechanism,
325 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
326 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_data_send (mechanism, out_data_len);
330 _g_dbus_auth_mechanism_client_shutdown (GDBusAuthMechanism *mechanism)
332 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
333 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_shutdown (mechanism);
336 /* ---------------------------------------------------------------------------------------------------- */