2 * Copyright (C) 2010 Wim Taymans <wim.taymans at gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 * @short_description: Roles and permissions for a client
22 * @see_also: #GstRTSPClient, #GstRTSPPermissions, #GstRTSPAuth
24 * A #GstRTSPToken contains the permissions and roles of the user
25 * performing the current request. A token is usually created when a user is
26 * authenticated by the #GstRTSPAuth object and is then placed as the current
27 * token for the current request.
29 * #GstRTSPAuth can use the token and its contents to check authorization for
30 * various operations by comparing the token to the #GstRTSPPermissions of the
33 * The accepted values of the token are entirely defined by the #GstRTSPAuth
34 * object that implements the security policy.
36 * Last reviewed on 2013-07-15 (1.0.0)
41 #include "rtsp-token.h"
43 typedef struct _GstRTSPTokenImpl
47 GstStructure *structure;
50 #define GST_RTSP_TOKEN_STRUCTURE(t) (((GstRTSPTokenImpl *)(t))->structure)
52 //GST_DEBUG_CATEGORY_STATIC (rtsp_token_debug);
53 //#define GST_CAT_DEFAULT rtsp_token_debug
55 GST_DEFINE_MINI_OBJECT_TYPE (GstRTSPToken, gst_rtsp_token);
57 static void gst_rtsp_token_init (GstRTSPTokenImpl * token,
58 GstStructure * structure);
61 _gst_rtsp_token_free (GstRTSPToken * token)
63 GstRTSPTokenImpl *impl = (GstRTSPTokenImpl *) token;
65 gst_structure_set_parent_refcount (impl->structure, NULL);
66 gst_structure_free (impl->structure);
68 g_slice_free1 (sizeof (GstRTSPTokenImpl), token);
72 _gst_rtsp_token_copy (GstRTSPTokenImpl * token)
74 GstRTSPTokenImpl *copy;
75 GstStructure *structure;
77 structure = gst_structure_copy (token->structure);
79 copy = g_slice_new0 (GstRTSPTokenImpl);
80 gst_rtsp_token_init (copy, structure);
82 return (GstRTSPToken *) copy;
86 gst_rtsp_token_init (GstRTSPTokenImpl * token, GstStructure * structure)
88 gst_mini_object_init (GST_MINI_OBJECT_CAST (token), 0,
90 (GstMiniObjectCopyFunction) _gst_rtsp_token_copy, NULL,
91 (GstMiniObjectFreeFunction) _gst_rtsp_token_free);
93 token->structure = structure;
94 gst_structure_set_parent_refcount (token->structure,
95 &token->token.mini_object.refcount);
99 * gst_rtsp_token_new_empty:
101 * Create a new empty Authorization token.
103 * Returns: (transfer full): a new empty authorization token.
106 gst_rtsp_token_new_empty (void)
108 GstRTSPTokenImpl *token;
111 s = gst_structure_new_empty ("GstRTSPToken");
112 g_return_val_if_fail (s != NULL, NULL);
114 token = g_slice_new0 (GstRTSPTokenImpl);
115 gst_rtsp_token_init (token, s);
117 return (GstRTSPToken *) token;
121 * gst_rtsp_token_new:
122 * @firstfield: the first fieldname
123 * @...: additional arguments
125 * Create a new Authorization token with the given fieldnames and values.
126 * Arguments are given similar to gst_structure_new().
128 * Returns: (transfer full): a new authorization token.
131 gst_rtsp_token_new (const gchar * firstfield, ...)
133 GstRTSPToken *result;
136 va_start (var_args, firstfield);
137 result = gst_rtsp_token_new_valist (firstfield, var_args);
144 * gst_rtsp_token_new_valist:
145 * @firstfield: the first fieldname
146 * @var_args: additional arguments
148 * Create a new Authorization token with the given fieldnames and values.
149 * Arguments are given similar to gst_structure_new_valist().
151 * Returns: (transfer full): a new authorization token.
154 gst_rtsp_token_new_valist (const gchar * firstfield, va_list var_args)
159 g_return_val_if_fail (firstfield != NULL, NULL);
161 token = gst_rtsp_token_new_empty ();
162 s = GST_RTSP_TOKEN_STRUCTURE (token);
163 gst_structure_set_valist (s, firstfield, var_args);
170 * gst_rtsp_token_get_structure:
171 * @token: The #GstRTSPToken.
173 * Access the structure of the token.
175 * Returns: (transfer none): The structure of the token. The structure is still
176 * owned by the token, which means that you should not free it and that the
177 * pointer becomes invalid when you free the token.
182 gst_rtsp_token_get_structure (GstRTSPToken * token)
184 g_return_val_if_fail (GST_IS_RTSP_TOKEN (token), NULL);
186 return GST_RTSP_TOKEN_STRUCTURE (token);
190 * gst_rtsp_token_writable_structure:
191 * @token: The #GstRTSPToken.
193 * Get a writable version of the structure.
195 * Returns: (transfer none): The structure of the token. The structure is still
196 * owned by the token, which means that you should not free it and that the
197 * pointer becomes invalid when you free the token. This function checks if
198 * @token is writable and will never return %NULL.
203 gst_rtsp_token_writable_structure (GstRTSPToken * token)
205 g_return_val_if_fail (GST_IS_RTSP_TOKEN (token), NULL);
206 g_return_val_if_fail (gst_mini_object_is_writable (GST_MINI_OBJECT_CAST
209 return GST_RTSP_TOKEN_STRUCTURE (token);
213 * gst_rtsp_token_get_string:
214 * @token: a #GstRTSPToken
215 * @field: a field name
217 * Get the string value of @field in @token.
219 * Returns: (transfer none) (nullable): the string value of @field in
220 * @token or %NULL when @field is not defined in @token. The string
221 * becomes invalid when you free @token.
224 gst_rtsp_token_get_string (GstRTSPToken * token, const gchar * field)
226 return gst_structure_get_string (GST_RTSP_TOKEN_STRUCTURE (token), field);
230 * gst_rtsp_token_is_allowed:
231 * @token: a #GstRTSPToken
232 * @field: a field name
234 * Check if @token has a boolean @field and if it is set to %TRUE.
236 * Returns: %TRUE if @token has a boolean field named @field set to %TRUE.
239 gst_rtsp_token_is_allowed (GstRTSPToken * token, const gchar * field)
243 g_return_val_if_fail (GST_IS_RTSP_TOKEN (token), FALSE);
244 g_return_val_if_fail (field != NULL, FALSE);
246 if (!gst_structure_get_boolean (GST_RTSP_TOKEN_STRUCTURE (token), field,