1 /* GStreamer
2  * Copyright (C) <2005,2006> Wim Taymans <wim@fluendo.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  * Unless otherwise indicated, Source Code is licensed under MIT license.
21  * See further explanation attached in License Statement (distributed in the file
22  * LICENSE).
23  *
24  * Permission is hereby granted, free of charge, to any person obtaining a copy of
25  * this software and associated documentation files (the "Software"), to deal in
26  * the Software without restriction, including without limitation the rights to
27  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
28  * of the Software, and to permit persons to whom the Software is furnished to do
29  * so, subject to the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be included in all
32  * copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40  * SOFTWARE.
41  */
42 
43 #ifndef __GST_RTSP_MESSAGE_H__
44 #define __GST_RTSP_MESSAGE_H__
45 
46 #include <gst/gst.h>
47 #include <gst/rtsp/gstrtspdefs.h>
48 
49 G_BEGIN_DECLS
50 
51 /**
52  * GstRTSPMsgType:
53  * @GST_RTSP_MESSAGE_INVALID: invalid message type
54  * @GST_RTSP_MESSAGE_REQUEST: RTSP request message
55  * @GST_RTSP_MESSAGE_RESPONSE: RTSP response message
56  * @GST_RTSP_MESSAGE_HTTP_REQUEST: HTTP request message.
57  * @GST_RTSP_MESSAGE_HTTP_RESPONSE: HTTP response message.
58  * @GST_RTSP_MESSAGE_DATA: data message
59  *
60  * The type of a message.
61  */
62 typedef enum
63 {
64   GST_RTSP_MESSAGE_INVALID,
65   GST_RTSP_MESSAGE_REQUEST,
66   GST_RTSP_MESSAGE_RESPONSE,
67   GST_RTSP_MESSAGE_HTTP_REQUEST,
68   GST_RTSP_MESSAGE_HTTP_RESPONSE,
69   GST_RTSP_MESSAGE_DATA
70 } GstRTSPMsgType;
71 
72 typedef struct _GstRTSPMessage GstRTSPMessage;
73 
74 /**
75  * GstRTSPMessage:
76  * @type: the message type
77  *
78  * An RTSP message containing request, response or data messages. Depending on
79  * the @type, the appropriate structure may be accessed.
80  */
81 struct _GstRTSPMessage
82 {
83   GstRTSPMsgType    type;
84 
85   union {
86     struct {
87       GstRTSPMethod      method;
88       gchar             *uri;
89       GstRTSPVersion     version;
90     } request;
91     struct {
92       GstRTSPStatusCode  code;
93       gchar             *reason;
94       GstRTSPVersion     version;
95     } response;
96     struct {
97       guint8             channel;
98     } data;
99   } type_data;
100 
101   /*< private >*/
102   GArray        *hdr_fields;
103 
104   guint8        *body;
105   guint          body_size;
106 
107   GstBuffer     *body_buffer;
108   gpointer _gst_reserved[GST_PADDING-1];
109 };
110 
111 GST_RTSP_API
112 GType                   gst_rtsp_msg_get_type            (void);
113 
114 #define GST_TYPE_RTSP_MESSAGE           (gst_rtsp_msg_get_type())
115 #define GST_RTSP_MESSAGE_CAST(object)   ((GstRTSPMessage *)(object))
116 #define GST_RTSP_MESSAGE(object)        (GST_RTSP_MESSAGE_CAST(object))
117 
118 /* memory management */
119 
120 GST_RTSP_API
121 GstRTSPResult      gst_rtsp_message_new             (GstRTSPMessage **msg);
122 
123 GST_RTSP_API
124 GstRTSPResult      gst_rtsp_message_init            (GstRTSPMessage *msg);
125 
126 GST_RTSP_API
127 GstRTSPResult      gst_rtsp_message_unset           (GstRTSPMessage *msg);
128 
129 GST_RTSP_API
130 GstRTSPResult      gst_rtsp_message_free            (GstRTSPMessage *msg);
131 GST_RTSP_API
132 GstRTSPResult      gst_rtsp_message_copy            (const GstRTSPMessage *msg,
133                                                      GstRTSPMessage **copy);
134 
135 GST_RTSP_API
136 GstRTSPMsgType     gst_rtsp_message_get_type        (GstRTSPMessage *msg);
137 
138 /* request */
139 
140 GST_RTSP_API
141 GstRTSPResult      gst_rtsp_message_new_request     (GstRTSPMessage **msg,
142                                                      GstRTSPMethod method,
143                                                      const gchar *uri);
144 
145 GST_RTSP_API
146 GstRTSPResult      gst_rtsp_message_init_request    (GstRTSPMessage *msg,
147                                                      GstRTSPMethod method,
148                                                      const gchar *uri);
149 
150 GST_RTSP_API
151 GstRTSPResult      gst_rtsp_message_parse_request   (GstRTSPMessage *msg,
152                                                      GstRTSPMethod *method,
153                                                      const gchar **uri,
154                                                      GstRTSPVersion *version);
155 
156 /* response */
157 
158 GST_RTSP_API
159 GstRTSPResult      gst_rtsp_message_new_response    (GstRTSPMessage **msg,
160                                                      GstRTSPStatusCode code,
161                                                      const gchar *reason,
162                                                      const GstRTSPMessage *request);
163 
164 GST_RTSP_API
165 GstRTSPResult      gst_rtsp_message_init_response   (GstRTSPMessage *msg,
166                                                      GstRTSPStatusCode code,
167                                                      const gchar *reason,
168                                                      const GstRTSPMessage *request);
169 
170 GST_RTSP_API
171 GstRTSPResult      gst_rtsp_message_parse_response  (GstRTSPMessage *msg,
172                                                      GstRTSPStatusCode *code,
173                                                      const gchar **reason,
174                                                      GstRTSPVersion *version);
175 
176 /* data */
177 
178 GST_RTSP_API
179 GstRTSPResult      gst_rtsp_message_new_data        (GstRTSPMessage **msg,
180                                                      guint8 channel);
181 
182 GST_RTSP_API
183 GstRTSPResult      gst_rtsp_message_init_data       (GstRTSPMessage *msg,
184                                                      guint8 channel);
185 
186 GST_RTSP_API
187 GstRTSPResult      gst_rtsp_message_parse_data      (GstRTSPMessage *msg,
188                                                      guint8 *channel);
189 
190 /* headers */
191 
192 GST_RTSP_API
193 GstRTSPResult      gst_rtsp_message_add_header      (GstRTSPMessage *msg,
194                                                      GstRTSPHeaderField field,
195                                                      const gchar *value);
196 
197 GST_RTSP_API
198 GstRTSPResult      gst_rtsp_message_take_header     (GstRTSPMessage *msg,
199                                                      GstRTSPHeaderField field,
200                                                      gchar *value);
201 
202 GST_RTSP_API
203 GstRTSPResult      gst_rtsp_message_remove_header   (GstRTSPMessage *msg,
204                                                      GstRTSPHeaderField field,
205                                                      gint indx);
206 
207 GST_RTSP_API
208 GstRTSPResult      gst_rtsp_message_get_header      (const GstRTSPMessage *msg,
209                                                      GstRTSPHeaderField field,
210                                                      gchar **value,
211                                                      gint indx);
212 
213 GST_RTSP_API
214 GstRTSPResult      gst_rtsp_message_add_header_by_name    (GstRTSPMessage * msg,
215                                                            const gchar    * header,
216                                                            const gchar    * value);
217 
218 GST_RTSP_API
219 GstRTSPResult      gst_rtsp_message_take_header_by_name   (GstRTSPMessage * msg,
220                                                            const gchar    * header,
221                                                            gchar          * value);
222 
223 GST_RTSP_API
224 GstRTSPResult      gst_rtsp_message_remove_header_by_name (GstRTSPMessage * msg,
225                                                            const gchar    * header,
226                                                            gint             index);
227 
228 GST_RTSP_API
229 GstRTSPResult      gst_rtsp_message_get_header_by_name    (GstRTSPMessage * msg,
230                                                            const gchar    * header,
231                                                            gchar         ** value,
232                                                            gint             index);
233 
234 /* header serialization */
235 
236 GST_RTSP_API
237 GstRTSPResult      gst_rtsp_message_append_headers  (const GstRTSPMessage *msg,
238                                                      GString *str);
239 
240 /* handling the body */
241 
242 GST_RTSP_API
243 GstRTSPResult      gst_rtsp_message_set_body        (GstRTSPMessage *msg,
244                                                      const guint8 *data,
245                                                      guint size);
246 
247 GST_RTSP_API
248 GstRTSPResult      gst_rtsp_message_take_body       (GstRTSPMessage *msg,
249                                                      guint8 *data,
250                                                      guint size);
251 
252 GST_RTSP_API
253 GstRTSPResult      gst_rtsp_message_get_body        (const GstRTSPMessage *msg,
254                                                      guint8 **data,
255                                                      guint *size);
256 
257 GST_RTSP_API
258 GstRTSPResult      gst_rtsp_message_steal_body      (GstRTSPMessage *msg,
259                                                      guint8 **data,
260                                                      guint *size);
261 
262 GST_RTSP_API
263 GstRTSPResult      gst_rtsp_message_set_body_buffer (GstRTSPMessage *msg,
264                                                      GstBuffer * buffer);
265 
266 GST_RTSP_API
267 GstRTSPResult      gst_rtsp_message_take_body_buffer(GstRTSPMessage *msg,
268                                                      GstBuffer * buffer);
269 
270 GST_RTSP_API
271 GstRTSPResult      gst_rtsp_message_get_body_buffer (const GstRTSPMessage *msg,
272                                                      GstBuffer ** buffer);
273 
274 GST_RTSP_API
275 GstRTSPResult      gst_rtsp_message_steal_body_buffer(GstRTSPMessage *msg,
276                                                       GstBuffer ** buffer);
277 
278 GST_RTSP_API
279 gboolean           gst_rtsp_message_has_body_buffer(const GstRTSPMessage *msg);
280 
281 typedef struct _GstRTSPAuthCredential GstRTSPAuthCredential;
282 typedef struct _GstRTSPAuthParam GstRTSPAuthParam;
283 
284 /**
285  * GstRTSPAuthCredential:
286  * @scheme: a #GstRTSPAuthMethod
287  * @params: A NULL-terminated array of #GstRTSPAuthParam
288  * @authorization: The authorization for the basic schem
289  *
290  * RTSP Authentication credentials
291  */
292 struct _GstRTSPAuthCredential {
293   GstRTSPAuthMethod scheme;
294 
295   /* For Basic/Digest WWW-Authenticate and Digest
296    * Authorization */
297   GstRTSPAuthParam **params; /* NULL terminated */
298 
299   /* For Basic Authorization */
300   gchar *authorization;
301 };
302 
303 /**
304  * GstRTSPAuthParam:
305  * @name: The name of the parameter
306  * @value: The value of the parameter
307  *
308  * RTSP Authentication parameter
309  */
310 struct _GstRTSPAuthParam {
311   gchar *name;
312   gchar *value;
313 };
314 
315 GST_RTSP_API
316 GstRTSPAuthParam *       gst_rtsp_auth_param_copy (GstRTSPAuthParam * param);
317 GST_RTSP_API
318 void                     gst_rtsp_auth_param_free (GstRTSPAuthParam * param);
319 
320 GST_RTSP_API
321 GstRTSPAuthCredential ** gst_rtsp_message_parse_auth_credentials (GstRTSPMessage * msg, GstRTSPHeaderField field);
322 
323 GST_RTSP_API
324 void                     gst_rtsp_auth_credentials_free (GstRTSPAuthCredential ** credentials);
325 
326 #define GST_TYPE_RTSP_AUTH_CREDENTIAL gst_rtsp_auth_credential_get_type()
327 
328 GST_RTSP_API
329 GType                    gst_rtsp_auth_credential_get_type (void);
330 
331 #define GST_TYPE_RTSP_AUTH_PARAM gst_rtsp_auth_param_get_type()
332 
333 GST_RTSP_API
334 GType                    gst_rtsp_auth_param_get_type (void);
335 
336 /* debug */
337 
338 GST_RTSP_API
339 GstRTSPResult      gst_rtsp_message_dump            (GstRTSPMessage *msg);
340 
341 G_END_DECLS
342 
343 #endif /* __GST_RTSP_MESSAGE_H__ */
344