2 * Copyright (C) <2005,2006> Wim Taymans <wim@fluendo.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.
20 * Unless otherwise indicated, Source Code is licensed under MIT license.
21 * See further explanation attached in License Statement (distributed in the file
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:
31 * The above copyright notice and this permission notice shall be included in all
32 * copies or substantial portions of the Software.
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
45 * @short_description: common RTSP defines
46 * @see_also: gstrtspurl, gstrtspconnection
48 * Provides common defines for the RTSP library.
50 * Last reviewed on 2007-07-24 (0.10.14)
55 #include "gstrtspdefs.h"
63 static const gchar *rtsp_methods[] = {
80 static struct rtsp_header rtsp_headers[] = {
82 {"Accept-Encoding", TRUE},
83 {"Accept-Language", TRUE},
85 {"Authorization", FALSE},
88 {"Cache-Control", TRUE},
89 {"Conference", FALSE},
91 {"Content-Base", FALSE},
92 {"Content-Encoding", TRUE},
93 {"Content-Language", TRUE},
94 {"Content-Length", FALSE},
95 {"Content-Location", FALSE},
96 {"Content-Type", FALSE},
101 {"If-Modified-Since", FALSE},
102 {"Last-Modified", FALSE},
103 {"Proxy-Authenticate", TRUE},
104 {"Proxy-Require", TRUE},
109 {"Retry-After", FALSE},
116 {"Unsupported", FALSE},
117 {"User-Agent", FALSE},
119 {"WWW-Authenticate", TRUE},
121 /* Real extensions */
122 {"ClientChallenge", FALSE},
123 {"RealChallenge1", FALSE},
124 {"RealChallenge2", FALSE},
125 {"RealChallenge3", FALSE},
126 {"Subscribe", FALSE},
129 {"CompanyID", FALSE},
131 {"RegionData", FALSE},
132 {"SupportsMaximumASMBandwidth", FALSE},
134 {"PlayerStarttime", FALSE},
143 /* WM extensions [MS-RTSP] Since 0.10.23 */
144 {"Accept-Charset", TRUE},
147 {"X-Accelerate-Streaming", FALSE},
148 {"X-Accept-Authentication", FALSE},
149 {"X-Accept-Proxy-Authentication", FALSE},
150 {"X-Broadcast-Id", FALSE},
151 {"X-Burst-Streaming", FALSE},
153 {"X-Player-Lag-Time", FALSE},
154 {"X-Playlist", FALSE},
155 {"X-Playlist-Change-Notice", FALSE},
156 {"X-Playlist-Gen-Id", FALSE},
157 {"X-Playlist-Seek-Id", FALSE},
158 {"X-Proxy-Client-Agent", FALSE},
159 {"X-Proxy-Client-Verb", FALSE},
160 {"X-Receding-PlaylistChange", FALSE},
161 {"X-RTP-Info", FALSE},
162 {"X-StartupProfile", FALSE},
165 {"Timestamp", FALSE},
168 {"Authentication-Info", FALSE},
171 {"X-Server-IP-Address", FALSE},
172 {"X-Sessioncookie", FALSE},
175 {"RTCP-Interval", FALSE},
183 #define DEF_STATUS(c, t) \
184 g_hash_table_insert (statuses, GUINT_TO_POINTER(c), (gpointer) t)
187 rtsp_init_status (void)
189 GHashTable *statuses = g_hash_table_new (NULL, NULL);
191 DEF_STATUS (GST_RTSP_STS_CONTINUE, "Continue");
192 DEF_STATUS (GST_RTSP_STS_OK, "OK");
193 DEF_STATUS (GST_RTSP_STS_CREATED, "Created");
194 DEF_STATUS (GST_RTSP_STS_LOW_ON_STORAGE, "Low on Storage Space");
195 DEF_STATUS (GST_RTSP_STS_MULTIPLE_CHOICES, "Multiple Choices");
196 DEF_STATUS (GST_RTSP_STS_MOVED_PERMANENTLY, "Moved Permanently");
197 DEF_STATUS (GST_RTSP_STS_MOVE_TEMPORARILY, "Move Temporarily");
198 DEF_STATUS (GST_RTSP_STS_SEE_OTHER, "See Other");
199 DEF_STATUS (GST_RTSP_STS_NOT_MODIFIED, "Not Modified");
200 DEF_STATUS (GST_RTSP_STS_USE_PROXY, "Use Proxy");
201 DEF_STATUS (GST_RTSP_STS_BAD_REQUEST, "Bad Request");
202 DEF_STATUS (GST_RTSP_STS_UNAUTHORIZED, "Unauthorized");
203 DEF_STATUS (GST_RTSP_STS_PAYMENT_REQUIRED, "Payment Required");
204 DEF_STATUS (GST_RTSP_STS_FORBIDDEN, "Forbidden");
205 DEF_STATUS (GST_RTSP_STS_NOT_FOUND, "Not Found");
206 DEF_STATUS (GST_RTSP_STS_METHOD_NOT_ALLOWED, "Method Not Allowed");
207 DEF_STATUS (GST_RTSP_STS_NOT_ACCEPTABLE, "Not Acceptable");
208 DEF_STATUS (GST_RTSP_STS_PROXY_AUTH_REQUIRED,
209 "Proxy Authentication Required");
210 DEF_STATUS (GST_RTSP_STS_REQUEST_TIMEOUT, "Request Time-out");
211 DEF_STATUS (GST_RTSP_STS_GONE, "Gone");
212 DEF_STATUS (GST_RTSP_STS_LENGTH_REQUIRED, "Length Required");
213 DEF_STATUS (GST_RTSP_STS_PRECONDITION_FAILED, "Precondition Failed");
214 DEF_STATUS (GST_RTSP_STS_REQUEST_ENTITY_TOO_LARGE,
215 "Request Entity Too Large");
216 DEF_STATUS (GST_RTSP_STS_REQUEST_URI_TOO_LARGE, "Request-URI Too Large");
217 DEF_STATUS (GST_RTSP_STS_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type");
218 DEF_STATUS (GST_RTSP_STS_PARAMETER_NOT_UNDERSTOOD,
219 "Parameter Not Understood");
220 DEF_STATUS (GST_RTSP_STS_CONFERENCE_NOT_FOUND, "Conference Not Found");
221 DEF_STATUS (GST_RTSP_STS_NOT_ENOUGH_BANDWIDTH, "Not Enough Bandwidth");
222 DEF_STATUS (GST_RTSP_STS_SESSION_NOT_FOUND, "Session Not Found");
223 DEF_STATUS (GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
224 "Method Not Valid in This State");
225 DEF_STATUS (GST_RTSP_STS_HEADER_FIELD_NOT_VALID_FOR_RESOURCE,
226 "Header Field Not Valid for Resource");
227 DEF_STATUS (GST_RTSP_STS_INVALID_RANGE, "Invalid Range");
228 DEF_STATUS (GST_RTSP_STS_PARAMETER_IS_READONLY, "Parameter Is Read-Only");
229 DEF_STATUS (GST_RTSP_STS_AGGREGATE_OPERATION_NOT_ALLOWED,
230 "Aggregate operation not allowed");
231 DEF_STATUS (GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED,
232 "Only aggregate operation allowed");
233 DEF_STATUS (GST_RTSP_STS_UNSUPPORTED_TRANSPORT, "Unsupported transport");
234 DEF_STATUS (GST_RTSP_STS_DESTINATION_UNREACHABLE, "Destination unreachable");
235 DEF_STATUS (GST_RTSP_STS_KEY_MANAGEMENT_FAILURE, "Key management failure");
236 DEF_STATUS (GST_RTSP_STS_INTERNAL_SERVER_ERROR, "Internal Server Error");
237 DEF_STATUS (GST_RTSP_STS_NOT_IMPLEMENTED, "Not Implemented");
238 DEF_STATUS (GST_RTSP_STS_BAD_GATEWAY, "Bad Gateway");
239 DEF_STATUS (GST_RTSP_STS_SERVICE_UNAVAILABLE, "Service Unavailable");
240 DEF_STATUS (GST_RTSP_STS_GATEWAY_TIMEOUT, "Gateway Time-out");
241 DEF_STATUS (GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED,
242 "RTSP Version not supported");
243 DEF_STATUS (GST_RTSP_STS_OPTION_NOT_SUPPORTED, "Option not supported");
249 * gst_rtsp_strresult:
250 * @result: a #GstRTSPResult
252 * Convert @result in a human readable string.
254 * Returns: a newly allocated string. g_free() after usage.
257 gst_rtsp_strresult (GstRTSPResult result)
261 return g_strdup ("OK");
263 return g_strdup ("System error");
265 return g_strdup ("Network error");
267 return g_strdup ("Generic error");
268 case GST_RTSP_EINVAL:
269 return g_strdup ("Invalid parameter specified");
271 return g_strdup ("Operation interrupted");
272 case GST_RTSP_ENOMEM:
273 return g_strdup ("Out of memory");
274 case GST_RTSP_ERESOLV:
275 return g_strdup ("Cannot resolve host");
276 case GST_RTSP_ENOTIMPL:
277 return g_strdup ("Function not implemented");
278 case GST_RTSP_EPARSE:
279 return g_strdup ("Parse error");
280 case GST_RTSP_EWSASTART:
281 return g_strdup ("Error on WSAStartup");
282 case GST_RTSP_EWSAVERSION:
283 return g_strdup ("Windows sockets are not version 0x202");
285 return g_strdup ("Received end-of-file");
286 case GST_RTSP_ENOTIP:
287 return g_strdup ("Host is not a valid IP address");
288 case GST_RTSP_ETIMEOUT:
289 return g_strdup ("Timeout while waiting for server response");
291 return g_strdup ("Tunnel GET request received");
292 case GST_RTSP_ETPOST:
293 return g_strdup ("Tunnel POST request received");
296 return g_strdup_printf ("Unknown error (%d)", result);
301 * gst_rtsp_method_as_text:
302 * @method: a #GstRTSPMethod
304 * Convert @method to a string.
306 * Returns: a string representation of @method.
309 gst_rtsp_method_as_text (GstRTSPMethod method)
313 if (method == GST_RTSP_INVALID)
317 while ((method & 1) == 0) {
321 return rtsp_methods[i];
325 * gst_rtsp_version_as_text:
326 * @version: a #GstRTSPVersion
328 * Convert @version to a string.
330 * Returns: a string representation of @version.
333 gst_rtsp_version_as_text (GstRTSPVersion version)
336 case GST_RTSP_VERSION_1_0:
339 case GST_RTSP_VERSION_1_1:
348 * gst_rtsp_header_as_text:
349 * @field: a #GstRTSPHeaderField
351 * Convert @field to a string.
353 * Returns: a string representation of @field.
356 gst_rtsp_header_as_text (GstRTSPHeaderField field)
358 if (field == GST_RTSP_HDR_INVALID)
361 return rtsp_headers[field - 1].name;
365 * gst_rtsp_status_as_text:
366 * @code: a #GstRTSPStatusCode
368 * Convert @code to a string.
370 * Returns: a string representation of @code.
373 gst_rtsp_status_as_text (GstRTSPStatusCode code)
375 static GHashTable *statuses;
377 if (G_UNLIKELY (statuses == NULL))
378 statuses = rtsp_init_status ();
380 return g_hash_table_lookup (statuses, GUINT_TO_POINTER (code));
384 * gst_rtsp_find_header_field:
385 * @header: a header string
387 * Convert @header to a #GstRTSPHeaderField.
389 * Returns: a #GstRTSPHeaderField for @header or #GST_RTSP_HDR_INVALID if the
390 * header field is unknown.
393 gst_rtsp_find_header_field (const gchar * header)
397 for (idx = 0; rtsp_headers[idx].name; idx++) {
398 if (g_ascii_strcasecmp (rtsp_headers[idx].name, header) == 0) {
402 return GST_RTSP_HDR_INVALID;
406 * gst_rtsp_find_method:
409 * Convert @method to a #GstRTSPMethod.
411 * Returns: a #GstRTSPMethod for @method or #GST_RTSP_INVALID if the
415 gst_rtsp_find_method (const gchar * method)
419 for (idx = 0; rtsp_methods[idx]; idx++) {
420 if (g_ascii_strcasecmp (rtsp_methods[idx], method) == 0) {
424 return GST_RTSP_INVALID;
428 * gst_rtsp_options_as_text:
429 * @options: one or more #GstRTSPMethod
431 * Convert @options to a string.
433 * Returns: a new string of @options. g_free() after usage.
436 gst_rtsp_options_as_text (GstRTSPMethod options)
440 str = g_string_new ("");
442 if (options & GST_RTSP_OPTIONS)
443 g_string_append (str, "OPTIONS, ");
444 if (options & GST_RTSP_DESCRIBE)
445 g_string_append (str, "DESCRIBE, ");
446 if (options & GST_RTSP_ANNOUNCE)
447 g_string_append (str, "ANNOUNCE, ");
448 if (options & GST_RTSP_GET_PARAMETER)
449 g_string_append (str, "GET_PARAMETER, ");
450 if (options & GST_RTSP_PAUSE)
451 g_string_append (str, "PAUSE, ");
452 if (options & GST_RTSP_PLAY)
453 g_string_append (str, "PLAY, ");
454 if (options & GST_RTSP_RECORD)
455 g_string_append (str, "RECORD, ");
456 if (options & GST_RTSP_REDIRECT)
457 g_string_append (str, "REDIRECT, ");
458 if (options & GST_RTSP_SETUP)
459 g_string_append (str, "SETUP, ");
460 if (options & GST_RTSP_SET_PARAMETER)
461 g_string_append (str, "SET_PARAMETER, ");
462 if (options & GST_RTSP_TEARDOWN)
463 g_string_append (str, "TEARDOWN, ");
465 /* remove trailing ", " if there is one */
467 str = g_string_truncate (str, str->len - 2);
469 return g_string_free (str, FALSE);
473 * gst_rtsp_options_from_text:
474 * @options: a comma separated list of options
476 * Convert the comma separated list @options to a #GstRTSPMethod bitwise or
477 * of methods. This functions is the reverse of gst_rtsp_options_as_text().
479 * Returns: a #GstRTSPMethod
484 gst_rtsp_options_from_text (const gchar * options)
486 GstRTSPMethod methods;
490 /* The string is like:
491 * OPTIONS, DESCRIBE, ANNOUNCE, PLAY, SETUP, ...
493 ostr = g_strsplit (options, ",", 0);
496 for (i = 0; ostr[i]; i++) {
498 GstRTSPMethod method;
500 stripped = g_strstrip (ostr[i]);
501 method = gst_rtsp_find_method (stripped);
503 /* keep bitfield of supported methods */
504 if (method != GST_RTSP_INVALID)
513 * gst_rtsp_header_allow_multiple:
514 * @field: a #GstRTSPHeaderField
516 * Check whether @field may appear multiple times in a message.
518 * Returns: %TRUE if multiple headers are allowed.
521 gst_rtsp_header_allow_multiple (GstRTSPHeaderField field)
523 if (field == GST_RTSP_HDR_INVALID)
526 return rtsp_headers[field - 1].multiple;