It is 'registered', not 'registred'
[glib.git] / gio / gdbusauthmechanism.c
blobc2559929b134ad77afba2cb09360bb362d3a5996
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>
23 #include "config.h"
25 #include "gdbusauthmechanism.h"
26 #include "gcredentials.h"
27 #include "gdbuserror.h"
28 #include "gioenumtypes.h"
29 #include "giostream.h"
31 #include "glibintl.h"
33 /* ---------------------------------------------------------------------------------------------------- */
35 struct _GDBusAuthMechanismPrivate
37 GIOStream *stream;
38 GCredentials *credentials;
41 enum
43 PROP_0,
44 PROP_STREAM,
45 PROP_CREDENTIALS
48 G_DEFINE_ABSTRACT_TYPE (GDBusAuthMechanism, _g_dbus_auth_mechanism, G_TYPE_OBJECT);
50 /* ---------------------------------------------------------------------------------------------------- */
52 static void
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);
65 static void
66 _g_dbus_auth_mechanism_get_property (GObject *object,
67 guint prop_id,
68 GValue *value,
69 GParamSpec *pspec)
71 GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object);
73 switch (prop_id)
75 case PROP_STREAM:
76 g_value_set_object (value, mechanism->priv->stream);
77 break;
79 case PROP_CREDENTIALS:
80 g_value_set_object (value, mechanism->priv->credentials);
81 break;
83 default:
84 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
85 break;
89 static void
90 _g_dbus_auth_mechanism_set_property (GObject *object,
91 guint prop_id,
92 const GValue *value,
93 GParamSpec *pspec)
95 GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object);
97 switch (prop_id)
99 case PROP_STREAM:
100 mechanism->priv->stream = g_value_dup_object (value);
101 break;
103 case PROP_CREDENTIALS:
104 mechanism->priv->credentials = g_value_dup_object (value);
105 break;
107 default:
108 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
109 break;
113 static void
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,
126 PROP_STREAM,
127 g_param_spec_object ("stream",
128 P_("IO Stream"),
129 P_("The underlying GIOStream used for I/O"),
130 G_TYPE_IO_STREAM,
131 G_PARAM_READABLE |
132 G_PARAM_WRITABLE |
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,
148 PROP_CREDENTIALS,
149 g_param_spec_object ("credentials",
150 P_("Credentials"),
151 P_("The credentials of the remote peer"),
152 G_TYPE_CREDENTIALS,
153 G_PARAM_READABLE |
154 G_PARAM_WRITABLE |
155 G_PARAM_CONSTRUCT_ONLY |
156 G_PARAM_STATIC_NAME |
157 G_PARAM_STATIC_BLURB |
158 G_PARAM_STATIC_NICK));
161 static void
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 /* ---------------------------------------------------------------------------------------------------- */
172 GIOStream *
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;
179 GCredentials *
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 /* ---------------------------------------------------------------------------------------------------- */
188 const gchar *
189 _g_dbus_auth_mechanism_get_name (GType mechanism_type)
191 const gchar *name;
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);
201 return name;
204 gint
205 _g_dbus_auth_mechanism_get_priority (GType mechanism_type)
207 gint priority;
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);
217 return priority;
220 /* ---------------------------------------------------------------------------------------------------- */
222 gboolean
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);
229 gchar *
230 _g_dbus_auth_mechanism_encode_data (GDBusAuthMechanism *mechanism,
231 const gchar *data,
232 gsize data_len,
233 gsize *out_data_len)
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);
240 gchar *
241 _g_dbus_auth_mechanism_decode_data (GDBusAuthMechanism *mechanism,
242 const gchar *data,
243 gsize data_len,
244 gsize *out_data_len)
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);
259 void
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);
268 void
269 _g_dbus_auth_mechanism_server_data_receive (GDBusAuthMechanism *mechanism,
270 const gchar *data,
271 gsize data_len)
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);
277 gchar *
278 _g_dbus_auth_mechanism_server_data_send (GDBusAuthMechanism *mechanism,
279 gsize *out_data_len)
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);
285 gchar *
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);
292 void
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);
308 gchar *
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);
317 void
318 _g_dbus_auth_mechanism_client_data_receive (GDBusAuthMechanism *mechanism,
319 const gchar *data,
320 gsize data_len)
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);
326 gchar *
327 _g_dbus_auth_mechanism_client_data_send (GDBusAuthMechanism *mechanism,
328 gsize *out_data_len)
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);
334 void
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 /* ---------------------------------------------------------------------------------------------------- */