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 G_OBJECT_CLASS (_g_dbus_auth_mechanism_parent_class)->finalize (object);
67 _g_dbus_auth_mechanism_get_property (GObject *object,
72 GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object);
77 g_value_set_object (value, mechanism->priv->stream);
80 case PROP_CREDENTIALS:
81 g_value_set_object (value, mechanism->priv->credentials);
85 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
91 _g_dbus_auth_mechanism_set_property (GObject *object,
96 GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object);
101 mechanism->priv->stream = g_value_dup_object (value);
104 case PROP_CREDENTIALS:
105 mechanism->priv->credentials = g_value_dup_object (value);
109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
115 _g_dbus_auth_mechanism_class_init (GDBusAuthMechanismClass *klass)
117 GObjectClass *gobject_class;
119 g_type_class_add_private (klass, sizeof (GDBusAuthMechanismPrivate));
121 gobject_class = G_OBJECT_CLASS (klass);
122 gobject_class->get_property = _g_dbus_auth_mechanism_get_property;
123 gobject_class->set_property = _g_dbus_auth_mechanism_set_property;
124 gobject_class->finalize = _g_dbus_auth_mechanism_finalize;
126 g_object_class_install_property (gobject_class,
128 g_param_spec_object ("stream",
130 P_("The underlying GIOStream used for I/O"),
134 G_PARAM_CONSTRUCT_ONLY |
135 G_PARAM_STATIC_NAME |
136 G_PARAM_STATIC_BLURB |
137 G_PARAM_STATIC_NICK));
140 * GDBusAuthMechanism:credentials:
142 * If authenticating as a server, this property contains the
143 * received credentials, if any.
145 * If authenticating as a client, the property contains the
146 * credentials that were sent, if any.
148 g_object_class_install_property (gobject_class,
150 g_param_spec_object ("credentials",
152 P_("The credentials of the remote peer"),
156 G_PARAM_CONSTRUCT_ONLY |
157 G_PARAM_STATIC_NAME |
158 G_PARAM_STATIC_BLURB |
159 G_PARAM_STATIC_NICK));
163 _g_dbus_auth_mechanism_init (GDBusAuthMechanism *mechanism)
165 /* not used for now */
166 mechanism->priv = G_TYPE_INSTANCE_GET_PRIVATE (mechanism,
167 G_TYPE_DBUS_AUTH_MECHANISM,
168 GDBusAuthMechanismPrivate);
171 /* ---------------------------------------------------------------------------------------------------- */
174 _g_dbus_auth_mechanism_get_stream (GDBusAuthMechanism *mechanism)
176 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
177 return mechanism->priv->stream;
181 _g_dbus_auth_mechanism_get_credentials (GDBusAuthMechanism *mechanism)
183 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
184 return mechanism->priv->credentials;
187 /* ---------------------------------------------------------------------------------------------------- */
190 _g_dbus_auth_mechanism_get_name (GType mechanism_type)
193 GDBusAuthMechanismClass *klass;
195 g_return_val_if_fail (g_type_is_a (mechanism_type, G_TYPE_DBUS_AUTH_MECHANISM), NULL);
197 klass = g_type_class_ref (mechanism_type);
198 g_assert (klass != NULL);
199 name = klass->get_name ();
200 //g_type_class_unref (klass);
206 _g_dbus_auth_mechanism_get_priority (GType mechanism_type)
209 GDBusAuthMechanismClass *klass;
211 g_return_val_if_fail (g_type_is_a (mechanism_type, G_TYPE_DBUS_AUTH_MECHANISM), 0);
213 klass = g_type_class_ref (mechanism_type);
214 g_assert (klass != NULL);
215 priority = klass->get_priority ();
216 //g_type_class_unref (klass);
221 /* ---------------------------------------------------------------------------------------------------- */
224 _g_dbus_auth_mechanism_is_supported (GDBusAuthMechanism *mechanism)
226 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), FALSE);
227 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->is_supported (mechanism);
231 _g_dbus_auth_mechanism_encode_data (GDBusAuthMechanism *mechanism,
236 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
237 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->encode_data (mechanism, data, data_len, out_data_len);
242 _g_dbus_auth_mechanism_decode_data (GDBusAuthMechanism *mechanism,
247 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
248 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->decode_data (mechanism, data, data_len, out_data_len);
251 /* ---------------------------------------------------------------------------------------------------- */
253 GDBusAuthMechanismState
254 _g_dbus_auth_mechanism_server_get_state (GDBusAuthMechanism *mechanism)
256 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), G_DBUS_AUTH_MECHANISM_STATE_INVALID);
257 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_get_state (mechanism);
261 _g_dbus_auth_mechanism_server_initiate (GDBusAuthMechanism *mechanism,
262 const gchar *initial_response,
263 gsize initial_response_len)
265 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
266 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_initiate (mechanism, initial_response, initial_response_len);
270 _g_dbus_auth_mechanism_server_data_receive (GDBusAuthMechanism *mechanism,
274 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
275 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_data_receive (mechanism, data, data_len);
279 _g_dbus_auth_mechanism_server_data_send (GDBusAuthMechanism *mechanism,
282 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
283 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_data_send (mechanism, out_data_len);
287 _g_dbus_auth_mechanism_server_get_reject_reason (GDBusAuthMechanism *mechanism)
289 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
290 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_get_reject_reason (mechanism);
294 _g_dbus_auth_mechanism_server_shutdown (GDBusAuthMechanism *mechanism)
296 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
297 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_shutdown (mechanism);
300 /* ---------------------------------------------------------------------------------------------------- */
302 GDBusAuthMechanismState
303 _g_dbus_auth_mechanism_client_get_state (GDBusAuthMechanism *mechanism)
305 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), G_DBUS_AUTH_MECHANISM_STATE_INVALID);
306 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_get_state (mechanism);
310 _g_dbus_auth_mechanism_client_initiate (GDBusAuthMechanism *mechanism,
311 gsize *out_initial_response_len)
313 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
314 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_initiate (mechanism,
315 out_initial_response_len);
319 _g_dbus_auth_mechanism_client_data_receive (GDBusAuthMechanism *mechanism,
323 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
324 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_data_receive (mechanism, data, data_len);
328 _g_dbus_auth_mechanism_client_data_send (GDBusAuthMechanism *mechanism,
331 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL);
332 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_data_send (mechanism, out_data_len);
336 _g_dbus_auth_mechanism_client_shutdown (GDBusAuthMechanism *mechanism)
338 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism));
339 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_shutdown (mechanism);
342 /* ---------------------------------------------------------------------------------------------------- */
344 #define __G_DBUS_AUTH_MECHANISM_C__
345 #include "gioaliasdef.c"