Add Friulian translation
[glib.git] / gio / gdbusauthmechanism.c
blobd00fc4c5599963df89fe2ee085f6d37806bc90db
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>
21 #include "config.h"
23 #include "gdbusauthmechanism.h"
24 #include "gcredentials.h"
25 #include "gdbuserror.h"
26 #include "gioenumtypes.h"
27 #include "giostream.h"
29 #include "glibintl.h"
31 /* ---------------------------------------------------------------------------------------------------- */
33 struct _GDBusAuthMechanismPrivate
35 GIOStream *stream;
36 GCredentials *credentials;
39 enum
41 PROP_0,
42 PROP_STREAM,
43 PROP_CREDENTIALS
46 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GDBusAuthMechanism, _g_dbus_auth_mechanism, G_TYPE_OBJECT)
48 /* ---------------------------------------------------------------------------------------------------- */
50 static void
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);
63 static void
64 _g_dbus_auth_mechanism_get_property (GObject *object,
65 guint prop_id,
66 GValue *value,
67 GParamSpec *pspec)
69 GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object);
71 switch (prop_id)
73 case PROP_STREAM:
74 g_value_set_object (value, mechanism->priv->stream);
75 break;
77 case PROP_CREDENTIALS:
78 g_value_set_object (value, mechanism->priv->credentials);
79 break;
81 default:
82 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
83 break;
87 static void
88 _g_dbus_auth_mechanism_set_property (GObject *object,
89 guint prop_id,
90 const GValue *value,
91 GParamSpec *pspec)
93 GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object);
95 switch (prop_id)
97 case PROP_STREAM:
98 mechanism->priv->stream = g_value_dup_object (value);
99 break;
101 case PROP_CREDENTIALS:
102 mechanism->priv->credentials = g_value_dup_object (value);
103 break;
105 default:
106 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
107 break;
111 static void
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,
122 PROP_STREAM,
123 g_param_spec_object ("stream",
124 P_("IO Stream"),
125 P_("The underlying GIOStream used for I/O"),
126 G_TYPE_IO_STREAM,
127 G_PARAM_READABLE |
128 G_PARAM_WRITABLE |
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,
144 PROP_CREDENTIALS,
145 g_param_spec_object ("credentials",
146 P_("Credentials"),
147 P_("The credentials of the remote peer"),
148 G_TYPE_CREDENTIALS,
149 G_PARAM_READABLE |
150 G_PARAM_WRITABLE |
151 G_PARAM_CONSTRUCT_ONLY |
152 G_PARAM_STATIC_NAME |
153 G_PARAM_STATIC_BLURB |
154 G_PARAM_STATIC_NICK));
157 static void
158 _g_dbus_auth_mechanism_init (GDBusAuthMechanism *mechanism)
160 mechanism->priv = _g_dbus_auth_mechanism_get_instance_private (mechanism);
163 /* ---------------------------------------------------------------------------------------------------- */
165 GIOStream *
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;
172 GCredentials *
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 /* ---------------------------------------------------------------------------------------------------- */
181 const gchar *
182 _g_dbus_auth_mechanism_get_name (GType mechanism_type)
184 const gchar *name;
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);
194 return name;
197 gint
198 _g_dbus_auth_mechanism_get_priority (GType mechanism_type)
200 gint priority;
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);
210 return priority;
213 /* ---------------------------------------------------------------------------------------------------- */
215 gboolean
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);
222 gchar *
223 _g_dbus_auth_mechanism_encode_data (GDBusAuthMechanism *mechanism,
224 const gchar *data,
225 gsize data_len,
226 gsize *out_data_len)
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);
233 gchar *
234 _g_dbus_auth_mechanism_decode_data (GDBusAuthMechanism *mechanism,
235 const gchar *data,
236 gsize data_len,
237 gsize *out_data_len)
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);
252 void
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);
261 void
262 _g_dbus_auth_mechanism_server_data_receive (GDBusAuthMechanism *mechanism,
263 const gchar *data,
264 gsize data_len)
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);
270 gchar *
271 _g_dbus_auth_mechanism_server_data_send (GDBusAuthMechanism *mechanism,
272 gsize *out_data_len)
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);
278 gchar *
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);
285 void
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);
301 gchar *
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);
310 void
311 _g_dbus_auth_mechanism_client_data_receive (GDBusAuthMechanism *mechanism,
312 const gchar *data,
313 gsize data_len)
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);
319 gchar *
320 _g_dbus_auth_mechanism_client_data_send (GDBusAuthMechanism *mechanism,
321 gsize *out_data_len)
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);
327 void
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 /* ---------------------------------------------------------------------------------------------------- */