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 (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 g_type_class_add_private (klass, sizeof (GDBusAuthMechanismPrivate));
120 gobject_class = G_OBJECT_CLASS (klass);
121 gobject_class->get_property = _g_dbus_auth_mechanism_get_property;
122 gobject_class->set_property = _g_dbus_auth_mechanism_set_property;
123 gobject_class->finalize = _g_dbus_auth_mechanism_finalize;
125 g_object_class_install_property (gobject_class,
127 g_param_spec_object ("stream",
129 P_("The underlying GIOStream used for I/O"),
133 G_PARAM_CONSTRUCT_ONLY |
134 G_PARAM_STATIC_NAME |
135 G_PARAM_STATIC_BLURB |
136 G_PARAM_STATIC_NICK));
139 * GDBusAuthMechanism:credentials:
141 * If authenticating as a server, this property contains the
142 * received credentials, if any.
144 * If authenticating as a client, the property contains the
145 * credentials that were sent, if any.
147 g_object_class_install_property (gobject_class,
149 g_param_spec_object ("credentials",
151 P_("The credentials of the remote peer"),
155 G_PARAM_CONSTRUCT_ONLY |
156 G_PARAM_STATIC_NAME |
157 G_PARAM_STATIC_BLURB |
158 G_PARAM_STATIC_NICK));
162 _g_dbus_auth_mechanism_init (GDBusAuthMechanism *mechanism)
164 /* not used for now */
165 mechanism->priv = G_TYPE_INSTANCE_GET_PRIVATE (mechanism,
166 G_TYPE_DBUS_AUTH_MECHANISM,
167 GDBusAuthMechanismPrivate);
170 /* ---------------------------------------------------------------------------------------------------- */
173 _g_dbus_auth_mechanism_get_stream (GDBusAuthMechanism *mechanism)
175 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
176 return mechanism->priv->stream;
180 _g_dbus_auth_mechanism_get_credentials (GDBusAuthMechanism *mechanism)
182 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
183 return mechanism->priv->credentials;
186 /* ---------------------------------------------------------------------------------------------------- */
189 _g_dbus_auth_mechanism_get_name (GType mechanism_type)
192 GDBusAuthMechanismClass *klass;
194 g_return_val_if_fail (g_type_is_a (mechanism_type, G_TYPE_DBUS_AUTH_MECHANISM), NULL);
196 klass = g_type_class_ref (mechanism_type);
197 g_assert (klass != NULL);
198 name = klass->get_name ();
199 //g_type_class_unref (klass);
205 _g_dbus_auth_mechanism_get_priority (GType mechanism_type)
208 GDBusAuthMechanismClass *klass;
210 g_return_val_if_fail (g_type_is_a (mechanism_type, G_TYPE_DBUS_AUTH_MECHANISM), 0);
212 klass = g_type_class_ref (mechanism_type);
213 g_assert (klass != NULL);
214 priority = klass->get_priority ();
215 //g_type_class_unref (klass);
220 /* ---------------------------------------------------------------------------------------------------- */
223 _g_dbus_auth_mechanism_is_supported (GDBusAuthMechanism *mechanism)
225 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), FALSE);
226 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->is_supported (mechanism);
230 _g_dbus_auth_mechanism_encode_data (GDBusAuthMechanism *mechanism,
235 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
236 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->encode_data (mechanism, data, data_len, out_data_len);
241 _g_dbus_auth_mechanism_decode_data (GDBusAuthMechanism *mechanism,
246 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
247 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->decode_data (mechanism, data, data_len, out_data_len);
250 /* ---------------------------------------------------------------------------------------------------- */
252 GDBusAuthMechanismState
253 _g_dbus_auth_mechanism_server_get_state (GDBusAuthMechanism *mechanism)
255 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), G_DBUS_AUTH_MECHANISM_STATE_INVALID);
256 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_get_state (mechanism);
260 _g_dbus_auth_mechanism_server_initiate (GDBusAuthMechanism *mechanism,
261 const gchar *initial_response,
262 gsize initial_response_len)
264 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
265 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_initiate (mechanism, initial_response, initial_response_len);
269 _g_dbus_auth_mechanism_server_data_receive (GDBusAuthMechanism *mechanism,
273 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
274 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_data_receive (mechanism, data, data_len);
278 _g_dbus_auth_mechanism_server_data_send (GDBusAuthMechanism *mechanism,
281 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
282 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_data_send (mechanism, out_data_len);
286 _g_dbus_auth_mechanism_server_get_reject_reason (GDBusAuthMechanism *mechanism)
288 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
289 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_get_reject_reason (mechanism);
293 _g_dbus_auth_mechanism_server_shutdown (GDBusAuthMechanism *mechanism)
295 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
296 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_shutdown (mechanism);
299 /* ---------------------------------------------------------------------------------------------------- */
301 GDBusAuthMechanismState
302 _g_dbus_auth_mechanism_client_get_state (GDBusAuthMechanism *mechanism)
304 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), G_DBUS_AUTH_MECHANISM_STATE_INVALID);
305 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_get_state (mechanism);
309 _g_dbus_auth_mechanism_client_initiate (GDBusAuthMechanism *mechanism,
310 gsize *out_initial_response_len)
312 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
313 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_initiate (mechanism,
314 out_initial_response_len);
318 _g_dbus_auth_mechanism_client_data_receive (GDBusAuthMechanism *mechanism,
322 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
323 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_data_receive (mechanism, data, data_len);
327 _g_dbus_auth_mechanism_client_data_send (GDBusAuthMechanism *mechanism,
330 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
331 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_data_send (mechanism, out_data_len);
335 _g_dbus_auth_mechanism_client_shutdown (GDBusAuthMechanism *mechanism)
337 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
338 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_shutdown (mechanism);
341 /* ---------------------------------------------------------------------------------------------------- */