docs: update docs
[platform/upstream/gstreamer.git] / gst / rtsp-server / rtsp-token.c
1 /* GStreamer
2  * Copyright (C) 2010 Wim Taymans <wim.taymans at gmail.com>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include <string.h>
21
22 #include "rtsp-token.h"
23
24 typedef struct _GstRTSPTokenImpl
25 {
26   GstRTSPToken token;
27
28   GstStructure *structure;
29 } GstRTSPTokenImpl;
30
31 #define GST_RTSP_TOKEN_STRUCTURE(t)  (((GstRTSPTokenImpl *)(t))->structure)
32
33 //GST_DEBUG_CATEGORY_STATIC (rtsp_token_debug);
34 //#define GST_CAT_DEFAULT rtsp_token_debug
35
36 GST_DEFINE_MINI_OBJECT_TYPE (GstRTSPToken, gst_rtsp_token);
37
38 static void gst_rtsp_token_init (GstRTSPTokenImpl * token,
39     GstStructure * structure);
40
41 static void
42 _gst_rtsp_token_free (GstRTSPToken * token)
43 {
44   GstRTSPTokenImpl *impl = (GstRTSPTokenImpl *) token;
45
46   gst_structure_set_parent_refcount (impl->structure, NULL);
47   gst_structure_free (impl->structure);
48
49   g_slice_free1 (sizeof (GstRTSPTokenImpl), token);
50 }
51
52 static GstRTSPToken *
53 _gst_rtsp_token_copy (GstRTSPTokenImpl * token)
54 {
55   GstRTSPTokenImpl *copy;
56   GstStructure *structure;
57
58   structure = gst_structure_copy (token->structure);
59
60   copy = g_slice_new0 (GstRTSPTokenImpl);
61   gst_rtsp_token_init (copy, structure);
62
63   return (GstRTSPToken *) copy;
64 }
65
66 static void
67 gst_rtsp_token_init (GstRTSPTokenImpl * token, GstStructure * structure)
68 {
69   gst_mini_object_init (GST_MINI_OBJECT_CAST (token), 0,
70       GST_TYPE_RTSP_TOKEN,
71       (GstMiniObjectCopyFunction) _gst_rtsp_token_copy, NULL,
72       (GstMiniObjectFreeFunction) _gst_rtsp_token_free);
73
74   token->structure = structure;
75   gst_structure_set_parent_refcount (token->structure,
76       &token->token.mini_object.refcount);
77 }
78
79 /**
80  * gst_rtsp_token_new:
81  *
82  * Create a new empty Authorization token.
83  *
84  * Returns: (transfer full): a new empty authorization token.
85  */
86 GstRTSPToken *
87 gst_rtsp_token_new (void)
88 {
89   GstRTSPTokenImpl *token;
90
91   token = g_slice_new0 (GstRTSPTokenImpl);
92
93   gst_rtsp_token_init (token, gst_structure_new_empty ("GstRTSPToken"));
94
95   return (GstRTSPToken *) token;
96 }
97
98
99 /**
100  * gst_rtsp_token_get_structure:
101  * @token: The #GstRTSPToken.
102  *
103  * Access the structure of the token.
104  *
105  * Returns: The structure of the token. The structure is still
106  * owned by the token, which means that you should not free it and
107  * that the pointer becomes invalid when you free the token.
108  *
109  * MT safe.
110  */
111 const GstStructure *
112 gst_rtsp_token_get_structure (GstRTSPToken * token)
113 {
114   g_return_val_if_fail (GST_IS_RTSP_TOKEN (token), NULL);
115
116   return GST_RTSP_TOKEN_STRUCTURE (token);
117 }
118
119 /**
120  * gst_rtsp_token_writable_structure:
121  * @token: The #GstRTSPToken.
122  *
123  * Get a writable version of the structure.
124  *
125  * Returns: The structure of the token. The structure is still
126  * owned by the token, which means that you should not free it and
127  * that the pointer becomes invalid when you free the token.
128  * This function checks if @token is writable and will never return NULL.
129  *
130  * MT safe.
131  */
132 GstStructure *
133 gst_rtsp_token_writable_structure (GstRTSPToken * token)
134 {
135   g_return_val_if_fail (GST_IS_RTSP_TOKEN (token), NULL);
136   g_return_val_if_fail (gst_mini_object_is_writable (GST_MINI_OBJECT_CAST
137           (token)), NULL);
138
139   return GST_RTSP_TOKEN_STRUCTURE (token);
140 }
141
142 /**
143  * gst_rtsp_token_get_string:
144  * @token: a #GstRTSPToken
145  * @field: a field name
146  *
147  * Get the string value of @field in @token.
148  *
149  * Returns: the string value of @field in @token or NULL when @field is not
150  * defined in @token.
151  */
152 const gchar *
153 gst_rtsp_token_get_string (GstRTSPToken * token, const gchar * field)
154 {
155   return gst_structure_get_string (GST_RTSP_TOKEN_STRUCTURE (token), field);
156 }