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, see <http://www.gnu.org/licenses/>.
18 * Author: David Zeuthen <davidz@redhat.com>
23 #include "gdbusauthmechanism.h"
24 #include "gcredentials.h"
25 #include "gdbuserror.h"
26 #include "gioenumtypes.h"
27 #include "giostream.h"
31 /* ---------------------------------------------------------------------------------------------------- */
33 struct _GDBusAuthMechanismPrivate
36 GCredentials
*credentials
;
46 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GDBusAuthMechanism
, _g_dbus_auth_mechanism
, G_TYPE_OBJECT
)
48 /* ---------------------------------------------------------------------------------------------------- */
51 _g_dbus_auth_mechanism_finalize (GObject
*object
)
53 GDBusAuthMechanism
*mechanism
= G_DBUS_AUTH_MECHANISM (object
);
55 if (mechanism
->priv
->stream
!= NULL
)
56 g_object_unref (mechanism
->priv
->stream
);
57 if (mechanism
->priv
->credentials
!= NULL
)
58 g_object_unref (mechanism
->priv
->credentials
);
60 G_OBJECT_CLASS (_g_dbus_auth_mechanism_parent_class
)->finalize (object
);
64 _g_dbus_auth_mechanism_get_property (GObject
*object
,
69 GDBusAuthMechanism
*mechanism
= G_DBUS_AUTH_MECHANISM (object
);
74 g_value_set_object (value
, mechanism
->priv
->stream
);
77 case PROP_CREDENTIALS
:
78 g_value_set_object (value
, mechanism
->priv
->credentials
);
82 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
88 _g_dbus_auth_mechanism_set_property (GObject
*object
,
93 GDBusAuthMechanism
*mechanism
= G_DBUS_AUTH_MECHANISM (object
);
98 mechanism
->priv
->stream
= g_value_dup_object (value
);
101 case PROP_CREDENTIALS
:
102 mechanism
->priv
->credentials
= g_value_dup_object (value
);
106 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
112 _g_dbus_auth_mechanism_class_init (GDBusAuthMechanismClass
*klass
)
114 GObjectClass
*gobject_class
;
116 gobject_class
= G_OBJECT_CLASS (klass
);
117 gobject_class
->get_property
= _g_dbus_auth_mechanism_get_property
;
118 gobject_class
->set_property
= _g_dbus_auth_mechanism_set_property
;
119 gobject_class
->finalize
= _g_dbus_auth_mechanism_finalize
;
121 g_object_class_install_property (gobject_class
,
123 g_param_spec_object ("stream",
125 P_("The underlying GIOStream used for I/O"),
129 G_PARAM_CONSTRUCT_ONLY
|
130 G_PARAM_STATIC_NAME
|
131 G_PARAM_STATIC_BLURB
|
132 G_PARAM_STATIC_NICK
));
135 * GDBusAuthMechanism:credentials:
137 * If authenticating as a server, this property contains the
138 * received credentials, if any.
140 * If authenticating as a client, the property contains the
141 * credentials that were sent, if any.
143 g_object_class_install_property (gobject_class
,
145 g_param_spec_object ("credentials",
147 P_("The credentials of the remote peer"),
151 G_PARAM_CONSTRUCT_ONLY
|
152 G_PARAM_STATIC_NAME
|
153 G_PARAM_STATIC_BLURB
|
154 G_PARAM_STATIC_NICK
));
158 _g_dbus_auth_mechanism_init (GDBusAuthMechanism
*mechanism
)
160 mechanism
->priv
= _g_dbus_auth_mechanism_get_instance_private (mechanism
);
163 /* ---------------------------------------------------------------------------------------------------- */
166 _g_dbus_auth_mechanism_get_stream (GDBusAuthMechanism
*mechanism
)
168 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism
), NULL
);
169 return mechanism
->priv
->stream
;
173 _g_dbus_auth_mechanism_get_credentials (GDBusAuthMechanism
*mechanism
)
175 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism
), NULL
);
176 return mechanism
->priv
->credentials
;
179 /* ---------------------------------------------------------------------------------------------------- */
182 _g_dbus_auth_mechanism_get_name (GType mechanism_type
)
185 GDBusAuthMechanismClass
*klass
;
187 g_return_val_if_fail (g_type_is_a (mechanism_type
, G_TYPE_DBUS_AUTH_MECHANISM
), NULL
);
189 klass
= g_type_class_ref (mechanism_type
);
190 g_assert (klass
!= NULL
);
191 name
= klass
->get_name ();
192 //g_type_class_unref (klass);
198 _g_dbus_auth_mechanism_get_priority (GType mechanism_type
)
201 GDBusAuthMechanismClass
*klass
;
203 g_return_val_if_fail (g_type_is_a (mechanism_type
, G_TYPE_DBUS_AUTH_MECHANISM
), 0);
205 klass
= g_type_class_ref (mechanism_type
);
206 g_assert (klass
!= NULL
);
207 priority
= klass
->get_priority ();
208 //g_type_class_unref (klass);
213 /* ---------------------------------------------------------------------------------------------------- */
216 _g_dbus_auth_mechanism_is_supported (GDBusAuthMechanism
*mechanism
)
218 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism
), FALSE
);
219 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism
)->is_supported (mechanism
);
223 _g_dbus_auth_mechanism_encode_data (GDBusAuthMechanism
*mechanism
,
228 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism
), NULL
);
229 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism
)->encode_data (mechanism
, data
, data_len
, out_data_len
);
234 _g_dbus_auth_mechanism_decode_data (GDBusAuthMechanism
*mechanism
,
239 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism
), NULL
);
240 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism
)->decode_data (mechanism
, data
, data_len
, out_data_len
);
243 /* ---------------------------------------------------------------------------------------------------- */
245 GDBusAuthMechanismState
246 _g_dbus_auth_mechanism_server_get_state (GDBusAuthMechanism
*mechanism
)
248 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism
), G_DBUS_AUTH_MECHANISM_STATE_INVALID
);
249 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism
)->server_get_state (mechanism
);
253 _g_dbus_auth_mechanism_server_initiate (GDBusAuthMechanism
*mechanism
,
254 const gchar
*initial_response
,
255 gsize initial_response_len
)
257 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism
));
258 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism
)->server_initiate (mechanism
, initial_response
, initial_response_len
);
262 _g_dbus_auth_mechanism_server_data_receive (GDBusAuthMechanism
*mechanism
,
266 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism
));
267 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism
)->server_data_receive (mechanism
, data
, data_len
);
271 _g_dbus_auth_mechanism_server_data_send (GDBusAuthMechanism
*mechanism
,
274 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism
), NULL
);
275 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism
)->server_data_send (mechanism
, out_data_len
);
279 _g_dbus_auth_mechanism_server_get_reject_reason (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_get_reject_reason (mechanism
);
286 _g_dbus_auth_mechanism_server_shutdown (GDBusAuthMechanism
*mechanism
)
288 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism
));
289 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism
)->server_shutdown (mechanism
);
292 /* ---------------------------------------------------------------------------------------------------- */
294 GDBusAuthMechanismState
295 _g_dbus_auth_mechanism_client_get_state (GDBusAuthMechanism
*mechanism
)
297 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism
), G_DBUS_AUTH_MECHANISM_STATE_INVALID
);
298 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism
)->client_get_state (mechanism
);
302 _g_dbus_auth_mechanism_client_initiate (GDBusAuthMechanism
*mechanism
,
303 gsize
*out_initial_response_len
)
305 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism
), NULL
);
306 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism
)->client_initiate (mechanism
,
307 out_initial_response_len
);
311 _g_dbus_auth_mechanism_client_data_receive (GDBusAuthMechanism
*mechanism
,
315 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism
));
316 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism
)->client_data_receive (mechanism
, data
, data_len
);
320 _g_dbus_auth_mechanism_client_data_send (GDBusAuthMechanism
*mechanism
,
323 g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism
), NULL
);
324 return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism
)->client_data_send (mechanism
, out_data_len
);
328 _g_dbus_auth_mechanism_client_shutdown (GDBusAuthMechanism
*mechanism
)
330 g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism
));
331 G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism
)->client_shutdown (mechanism
);
334 /* ---------------------------------------------------------------------------------------------------- */