/src/tinysparql/subprojects/glib-2.80.3/gio/gdbusauthmechanism.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* GDBus - GLib D-Bus Library |
2 | | * |
3 | | * Copyright (C) 2008-2010 Red Hat, Inc. |
4 | | * |
5 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
6 | | * |
7 | | * This library is free software; you can redistribute it and/or |
8 | | * modify it under the terms of the GNU Lesser General Public |
9 | | * License as published by the Free Software Foundation; either |
10 | | * version 2.1 of the License, or (at your option) any later version. |
11 | | * |
12 | | * This library is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | | * Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General |
18 | | * Public License along with this library; if not, see <http://www.gnu.org/licenses/>. |
19 | | * |
20 | | * Author: David Zeuthen <davidz@redhat.com> |
21 | | */ |
22 | | |
23 | | #include "config.h" |
24 | | |
25 | | #include "gdbusauthmechanism.h" |
26 | | #include "gcredentials.h" |
27 | | #include "gdbuserror.h" |
28 | | #include "gioenumtypes.h" |
29 | | #include "giostream.h" |
30 | | |
31 | | #include "glibintl.h" |
32 | | |
33 | | /* ---------------------------------------------------------------------------------------------------- */ |
34 | | |
35 | | struct _GDBusAuthMechanismPrivate |
36 | | { |
37 | | GIOStream *stream; |
38 | | GCredentials *credentials; |
39 | | }; |
40 | | |
41 | | enum |
42 | | { |
43 | | PROP_0, |
44 | | PROP_STREAM, |
45 | | PROP_CREDENTIALS |
46 | | }; |
47 | | |
48 | | G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GDBusAuthMechanism, _g_dbus_auth_mechanism, G_TYPE_OBJECT) |
49 | | |
50 | | /* ---------------------------------------------------------------------------------------------------- */ |
51 | | |
52 | | static void |
53 | | _g_dbus_auth_mechanism_finalize (GObject *object) |
54 | 0 | { |
55 | 0 | GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object); |
56 | |
|
57 | 0 | if (mechanism->priv->stream != NULL) |
58 | 0 | g_object_unref (mechanism->priv->stream); |
59 | 0 | if (mechanism->priv->credentials != NULL) |
60 | 0 | g_object_unref (mechanism->priv->credentials); |
61 | |
|
62 | 0 | G_OBJECT_CLASS (_g_dbus_auth_mechanism_parent_class)->finalize (object); |
63 | 0 | } |
64 | | |
65 | | static void |
66 | | _g_dbus_auth_mechanism_get_property (GObject *object, |
67 | | guint prop_id, |
68 | | GValue *value, |
69 | | GParamSpec *pspec) |
70 | 0 | { |
71 | 0 | GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object); |
72 | |
|
73 | 0 | switch (prop_id) |
74 | 0 | { |
75 | 0 | case PROP_STREAM: |
76 | 0 | g_value_set_object (value, mechanism->priv->stream); |
77 | 0 | break; |
78 | | |
79 | 0 | case PROP_CREDENTIALS: |
80 | 0 | g_value_set_object (value, mechanism->priv->credentials); |
81 | 0 | break; |
82 | | |
83 | 0 | default: |
84 | 0 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
85 | 0 | break; |
86 | 0 | } |
87 | 0 | } |
88 | | |
89 | | static void |
90 | | _g_dbus_auth_mechanism_set_property (GObject *object, |
91 | | guint prop_id, |
92 | | const GValue *value, |
93 | | GParamSpec *pspec) |
94 | 0 | { |
95 | 0 | GDBusAuthMechanism *mechanism = G_DBUS_AUTH_MECHANISM (object); |
96 | |
|
97 | 0 | switch (prop_id) |
98 | 0 | { |
99 | 0 | case PROP_STREAM: |
100 | 0 | mechanism->priv->stream = g_value_dup_object (value); |
101 | 0 | break; |
102 | | |
103 | 0 | case PROP_CREDENTIALS: |
104 | 0 | mechanism->priv->credentials = g_value_dup_object (value); |
105 | 0 | break; |
106 | | |
107 | 0 | default: |
108 | 0 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
109 | 0 | break; |
110 | 0 | } |
111 | 0 | } |
112 | | |
113 | | static void |
114 | | _g_dbus_auth_mechanism_class_init (GDBusAuthMechanismClass *klass) |
115 | 0 | { |
116 | 0 | GObjectClass *gobject_class; |
117 | |
|
118 | 0 | gobject_class = G_OBJECT_CLASS (klass); |
119 | 0 | gobject_class->get_property = _g_dbus_auth_mechanism_get_property; |
120 | 0 | gobject_class->set_property = _g_dbus_auth_mechanism_set_property; |
121 | 0 | gobject_class->finalize = _g_dbus_auth_mechanism_finalize; |
122 | |
|
123 | 0 | g_object_class_install_property (gobject_class, |
124 | 0 | PROP_STREAM, |
125 | 0 | g_param_spec_object ("stream", NULL, NULL, |
126 | 0 | G_TYPE_IO_STREAM, |
127 | 0 | G_PARAM_READABLE | |
128 | 0 | G_PARAM_WRITABLE | |
129 | 0 | G_PARAM_CONSTRUCT_ONLY | |
130 | 0 | G_PARAM_STATIC_NAME | |
131 | 0 | G_PARAM_STATIC_BLURB | |
132 | 0 | G_PARAM_STATIC_NICK)); |
133 | | |
134 | | /** |
135 | | * GDBusAuthMechanism:credentials: |
136 | | * |
137 | | * If authenticating as a server, this property contains the |
138 | | * received credentials, if any. |
139 | | * |
140 | | * If authenticating as a client, the property contains the |
141 | | * credentials that were sent, if any. |
142 | | */ |
143 | 0 | g_object_class_install_property (gobject_class, |
144 | 0 | PROP_CREDENTIALS, |
145 | 0 | g_param_spec_object ("credentials", NULL, NULL, |
146 | 0 | G_TYPE_CREDENTIALS, |
147 | 0 | G_PARAM_READABLE | |
148 | 0 | G_PARAM_WRITABLE | |
149 | 0 | G_PARAM_CONSTRUCT_ONLY | |
150 | 0 | G_PARAM_STATIC_NAME | |
151 | 0 | G_PARAM_STATIC_BLURB | |
152 | 0 | G_PARAM_STATIC_NICK)); |
153 | 0 | } |
154 | | |
155 | | static void |
156 | | _g_dbus_auth_mechanism_init (GDBusAuthMechanism *mechanism) |
157 | 0 | { |
158 | 0 | mechanism->priv = _g_dbus_auth_mechanism_get_instance_private (mechanism); |
159 | 0 | } |
160 | | |
161 | | /* ---------------------------------------------------------------------------------------------------- */ |
162 | | |
163 | | GIOStream * |
164 | | _g_dbus_auth_mechanism_get_stream (GDBusAuthMechanism *mechanism) |
165 | 0 | { |
166 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
167 | 0 | return mechanism->priv->stream; |
168 | 0 | } |
169 | | |
170 | | GCredentials * |
171 | | _g_dbus_auth_mechanism_get_credentials (GDBusAuthMechanism *mechanism) |
172 | 0 | { |
173 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
174 | 0 | return mechanism->priv->credentials; |
175 | 0 | } |
176 | | |
177 | | /* ---------------------------------------------------------------------------------------------------- */ |
178 | | |
179 | | const gchar * |
180 | | _g_dbus_auth_mechanism_get_name (GType mechanism_type) |
181 | 0 | { |
182 | 0 | const gchar *name; |
183 | 0 | GDBusAuthMechanismClass *klass; |
184 | |
|
185 | 0 | g_return_val_if_fail (g_type_is_a (mechanism_type, G_TYPE_DBUS_AUTH_MECHANISM), NULL); |
186 | | |
187 | 0 | klass = g_type_class_ref (mechanism_type); |
188 | 0 | g_assert (klass != NULL); |
189 | 0 | name = klass->get_name (); |
190 | | //g_type_class_unref (klass); |
191 | |
|
192 | 0 | return name; |
193 | 0 | } |
194 | | |
195 | | gint |
196 | | _g_dbus_auth_mechanism_get_priority (GType mechanism_type) |
197 | 0 | { |
198 | 0 | gint priority; |
199 | 0 | GDBusAuthMechanismClass *klass; |
200 | |
|
201 | 0 | g_return_val_if_fail (g_type_is_a (mechanism_type, G_TYPE_DBUS_AUTH_MECHANISM), 0); |
202 | | |
203 | 0 | klass = g_type_class_ref (mechanism_type); |
204 | 0 | g_assert (klass != NULL); |
205 | 0 | priority = klass->get_priority (); |
206 | | //g_type_class_unref (klass); |
207 | |
|
208 | 0 | return priority; |
209 | 0 | } |
210 | | |
211 | | /* ---------------------------------------------------------------------------------------------------- */ |
212 | | |
213 | | gboolean |
214 | | _g_dbus_auth_mechanism_is_supported (GDBusAuthMechanism *mechanism) |
215 | 0 | { |
216 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), FALSE); |
217 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->is_supported (mechanism); |
218 | 0 | } |
219 | | |
220 | | gchar * |
221 | | _g_dbus_auth_mechanism_encode_data (GDBusAuthMechanism *mechanism, |
222 | | const gchar *data, |
223 | | gsize data_len, |
224 | | gsize *out_data_len) |
225 | 0 | { |
226 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
227 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->encode_data (mechanism, data, data_len, out_data_len); |
228 | 0 | } |
229 | | |
230 | | |
231 | | gchar * |
232 | | _g_dbus_auth_mechanism_decode_data (GDBusAuthMechanism *mechanism, |
233 | | const gchar *data, |
234 | | gsize data_len, |
235 | | gsize *out_data_len) |
236 | 0 | { |
237 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
238 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->decode_data (mechanism, data, data_len, out_data_len); |
239 | 0 | } |
240 | | |
241 | | /* ---------------------------------------------------------------------------------------------------- */ |
242 | | |
243 | | GDBusAuthMechanismState |
244 | | _g_dbus_auth_mechanism_server_get_state (GDBusAuthMechanism *mechanism) |
245 | 0 | { |
246 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), G_DBUS_AUTH_MECHANISM_STATE_INVALID); |
247 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_get_state (mechanism); |
248 | 0 | } |
249 | | |
250 | | void |
251 | | _g_dbus_auth_mechanism_server_initiate (GDBusAuthMechanism *mechanism, |
252 | | const gchar *initial_response, |
253 | | gsize initial_response_len) |
254 | 0 | { |
255 | 0 | g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism)); |
256 | 0 | G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_initiate (mechanism, initial_response, initial_response_len); |
257 | 0 | } |
258 | | |
259 | | void |
260 | | _g_dbus_auth_mechanism_server_data_receive (GDBusAuthMechanism *mechanism, |
261 | | const gchar *data, |
262 | | gsize data_len) |
263 | 0 | { |
264 | 0 | g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism)); |
265 | 0 | G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_data_receive (mechanism, data, data_len); |
266 | 0 | } |
267 | | |
268 | | gchar * |
269 | | _g_dbus_auth_mechanism_server_data_send (GDBusAuthMechanism *mechanism, |
270 | | gsize *out_data_len) |
271 | 0 | { |
272 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
273 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_data_send (mechanism, out_data_len); |
274 | 0 | } |
275 | | |
276 | | gchar * |
277 | | _g_dbus_auth_mechanism_server_get_reject_reason (GDBusAuthMechanism *mechanism) |
278 | 0 | { |
279 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
280 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_get_reject_reason (mechanism); |
281 | 0 | } |
282 | | |
283 | | void |
284 | | _g_dbus_auth_mechanism_server_shutdown (GDBusAuthMechanism *mechanism) |
285 | 0 | { |
286 | 0 | g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism)); |
287 | 0 | G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->server_shutdown (mechanism); |
288 | 0 | } |
289 | | |
290 | | /* ---------------------------------------------------------------------------------------------------- */ |
291 | | |
292 | | GDBusAuthMechanismState |
293 | | _g_dbus_auth_mechanism_client_get_state (GDBusAuthMechanism *mechanism) |
294 | 0 | { |
295 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), G_DBUS_AUTH_MECHANISM_STATE_INVALID); |
296 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_get_state (mechanism); |
297 | 0 | } |
298 | | |
299 | | gchar * |
300 | | _g_dbus_auth_mechanism_client_initiate (GDBusAuthMechanism *mechanism, |
301 | | GDBusConnectionFlags conn_flags, |
302 | | gsize *out_initial_response_len) |
303 | 0 | { |
304 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
305 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_initiate (mechanism, |
306 | 0 | conn_flags, |
307 | 0 | out_initial_response_len); |
308 | 0 | } |
309 | | |
310 | | void |
311 | | _g_dbus_auth_mechanism_client_data_receive (GDBusAuthMechanism *mechanism, |
312 | | const gchar *data, |
313 | | gsize data_len) |
314 | 0 | { |
315 | 0 | g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism)); |
316 | 0 | G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_data_receive (mechanism, data, data_len); |
317 | 0 | } |
318 | | |
319 | | gchar * |
320 | | _g_dbus_auth_mechanism_client_data_send (GDBusAuthMechanism *mechanism, |
321 | | gsize *out_data_len) |
322 | 0 | { |
323 | 0 | g_return_val_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism), NULL); |
324 | 0 | return G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_data_send (mechanism, out_data_len); |
325 | 0 | } |
326 | | |
327 | | void |
328 | | _g_dbus_auth_mechanism_client_shutdown (GDBusAuthMechanism *mechanism) |
329 | 0 | { |
330 | 0 | g_return_if_fail (G_IS_DBUS_AUTH_MECHANISM (mechanism)); |
331 | 0 | G_DBUS_AUTH_MECHANISM_GET_CLASS (mechanism)->client_shutdown (mechanism); |
332 | 0 | } |
333 | | |
334 | | /* ---------------------------------------------------------------------------------------------------- */ |