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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, 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
50 * Provides common defines for the RTSP library.
54 * Last reviewed on 2007-07-24 (0.10.14)
59 #include "gstrtspdefs.h"
73 static const gchar *rtsp_results[] = {
77 "Invalid parameter specified",
78 "Operation interrupted",
80 "Cannot resolve host",
81 "Function not implemented",
84 "Error on WSAStartup",
85 "Windows sockets are not version 0x202",
86 "Received end-of-file",
88 "Host is not a valid IP address",
89 "Timeout while waiting for server response",
90 "Tunnel GET request received",
91 "Tunnel POST request received",
96 static const gchar *rtsp_methods[] = {
113 static struct rtsp_header rtsp_headers[] = {
115 {"Accept-Encoding", TRUE},
116 {"Accept-Language", TRUE},
118 {"Authorization", FALSE},
119 {"Bandwidth", FALSE},
120 {"Blocksize", FALSE},
121 {"Cache-Control", TRUE},
122 {"Conference", FALSE},
123 {"Connection", TRUE},
124 {"Content-Base", FALSE},
125 {"Content-Encoding", TRUE},
126 {"Content-Language", TRUE},
127 {"Content-Length", FALSE},
128 {"Content-Location", FALSE},
129 {"Content-Type", FALSE},
134 {"If-Modified-Since", FALSE},
135 {"Last-Modified", FALSE},
136 {"Proxy-Authenticate", TRUE},
137 {"Proxy-Require", TRUE},
142 {"Retry-After", FALSE},
149 {"Unsupported", FALSE},
150 {"User-Agent", FALSE},
152 {"WWW-Authenticate", TRUE},
154 /* Real extensions */
155 {"ClientChallenge", FALSE},
156 {"RealChallenge1", FALSE},
157 {"RealChallenge2", FALSE},
158 {"RealChallenge3", FALSE},
159 {"Subscribe", FALSE},
162 {"CompanyID", FALSE},
164 {"RegionData", FALSE},
165 {"SupportsMaximumASMBandwidth", FALSE},
167 {"PlayerStarttime", FALSE},
176 /* WM extensions [MS-RTSP] Since 0.10.23 */
177 {"Accept-Charset", TRUE},
180 {"X-Accelerate-Streaming", FALSE},
181 {"X-Accept-Authentication", FALSE},
182 {"X-Accept-Proxy-Authentication", FALSE},
183 {"X-Broadcast-Id", FALSE},
184 {"X-Burst-Streaming", FALSE},
186 {"X-Player-Lag-Time", FALSE},
187 {"X-Playlist", FALSE},
188 {"X-Playlist-Change-Notice", FALSE},
189 {"X-Playlist-Gen-Id", FALSE},
190 {"X-Playlist-Seek-Id", FALSE},
191 {"X-Proxy-Client-Agent", FALSE},
192 {"X-Proxy-Client-Verb", FALSE},
193 {"X-Receding-PlaylistChange", FALSE},
194 {"X-RTP-Info", FALSE},
195 {"X-StartupProfile", FALSE},
198 {"Timestamp", FALSE},
201 {"Authentication-Info", FALSE},
204 {"X-Server-IP-Address", FALSE},
205 {"X-Sessioncookie", FALSE},
210 #define DEF_STATUS(c, t) \
211 g_hash_table_insert (statuses, GUINT_TO_POINTER(c), (gpointer) t)
214 rtsp_init_status (void)
216 GHashTable *statuses = g_hash_table_new (NULL, NULL);
218 DEF_STATUS (GST_RTSP_STS_CONTINUE, "Continue");
219 DEF_STATUS (GST_RTSP_STS_OK, "OK");
220 DEF_STATUS (GST_RTSP_STS_CREATED, "Created");
221 DEF_STATUS (GST_RTSP_STS_LOW_ON_STORAGE, "Low on Storage Space");
222 DEF_STATUS (GST_RTSP_STS_MULTIPLE_CHOICES, "Multiple Choices");
223 DEF_STATUS (GST_RTSP_STS_MOVED_PERMANENTLY, "Moved Permanently");
224 DEF_STATUS (GST_RTSP_STS_MOVE_TEMPORARILY, "Move Temporarily");
225 DEF_STATUS (GST_RTSP_STS_SEE_OTHER, "See Other");
226 DEF_STATUS (GST_RTSP_STS_NOT_MODIFIED, "Not Modified");
227 DEF_STATUS (GST_RTSP_STS_USE_PROXY, "Use Proxy");
228 DEF_STATUS (GST_RTSP_STS_BAD_REQUEST, "Bad Request");
229 DEF_STATUS (GST_RTSP_STS_UNAUTHORIZED, "Unauthorized");
230 DEF_STATUS (GST_RTSP_STS_PAYMENT_REQUIRED, "Payment Required");
231 DEF_STATUS (GST_RTSP_STS_FORBIDDEN, "Forbidden");
232 DEF_STATUS (GST_RTSP_STS_NOT_FOUND, "Not Found");
233 DEF_STATUS (GST_RTSP_STS_METHOD_NOT_ALLOWED, "Method Not Allowed");
234 DEF_STATUS (GST_RTSP_STS_NOT_ACCEPTABLE, "Not Acceptable");
235 DEF_STATUS (GST_RTSP_STS_PROXY_AUTH_REQUIRED,
236 "Proxy Authentication Required");
237 DEF_STATUS (GST_RTSP_STS_REQUEST_TIMEOUT, "Request Time-out");
238 DEF_STATUS (GST_RTSP_STS_GONE, "Gone");
239 DEF_STATUS (GST_RTSP_STS_LENGTH_REQUIRED, "Length Required");
240 DEF_STATUS (GST_RTSP_STS_PRECONDITION_FAILED, "Precondition Failed");
241 DEF_STATUS (GST_RTSP_STS_REQUEST_ENTITY_TOO_LARGE,
242 "Request Entity Too Large");
243 DEF_STATUS (GST_RTSP_STS_REQUEST_URI_TOO_LARGE, "Request-URI Too Large");
244 DEF_STATUS (GST_RTSP_STS_UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type");
245 DEF_STATUS (GST_RTSP_STS_PARAMETER_NOT_UNDERSTOOD,
246 "Parameter Not Understood");
247 DEF_STATUS (GST_RTSP_STS_CONFERENCE_NOT_FOUND, "Conference Not Found");
248 DEF_STATUS (GST_RTSP_STS_NOT_ENOUGH_BANDWIDTH, "Not Enough Bandwidth");
249 DEF_STATUS (GST_RTSP_STS_SESSION_NOT_FOUND, "Session Not Found");
250 DEF_STATUS (GST_RTSP_STS_METHOD_NOT_VALID_IN_THIS_STATE,
251 "Method Not Valid in This State");
252 DEF_STATUS (GST_RTSP_STS_HEADER_FIELD_NOT_VALID_FOR_RESOURCE,
253 "Header Field Not Valid for Resource");
254 DEF_STATUS (GST_RTSP_STS_INVALID_RANGE, "Invalid Range");
255 DEF_STATUS (GST_RTSP_STS_PARAMETER_IS_READONLY, "Parameter Is Read-Only");
256 DEF_STATUS (GST_RTSP_STS_AGGREGATE_OPERATION_NOT_ALLOWED,
257 "Aggregate operation not allowed");
258 DEF_STATUS (GST_RTSP_STS_ONLY_AGGREGATE_OPERATION_ALLOWED,
259 "Only aggregate operation allowed");
260 DEF_STATUS (GST_RTSP_STS_UNSUPPORTED_TRANSPORT, "Unsupported transport");
261 DEF_STATUS (GST_RTSP_STS_DESTINATION_UNREACHABLE, "Destination unreachable");
262 DEF_STATUS (GST_RTSP_STS_INTERNAL_SERVER_ERROR, "Internal Server Error");
263 DEF_STATUS (GST_RTSP_STS_NOT_IMPLEMENTED, "Not Implemented");
264 DEF_STATUS (GST_RTSP_STS_BAD_GATEWAY, "Bad Gateway");
265 DEF_STATUS (GST_RTSP_STS_SERVICE_UNAVAILABLE, "Service Unavailable");
266 DEF_STATUS (GST_RTSP_STS_GATEWAY_TIMEOUT, "Gateway Time-out");
267 DEF_STATUS (GST_RTSP_STS_RTSP_VERSION_NOT_SUPPORTED,
268 "RTSP Version not supported");
269 DEF_STATUS (GST_RTSP_STS_OPTION_NOT_SUPPORTED, "Option not supported");
275 * gst_rtsp_strresult:
276 * @result: a #GstRTSPResult
278 * Convert @result in a human readable string.
280 * Returns: a newly allocated string. g_free() after usage.
283 gst_rtsp_strresult (GstRTSPResult result)
289 idx = CLAMP (idx, 0, -GST_RTSP_ELAST);
296 gchar *msg = g_win32_error_message (WSAGetLastError ());
297 res = g_strdup_printf (rtsp_results[idx], msg);
303 res = g_strdup_printf (rtsp_results[idx], g_strerror (errno));
306 res = g_strdup_printf (rtsp_results[idx], hstrerror (h_errno));
309 case -GST_RTSP_ELAST:
310 res = g_strdup_printf (rtsp_results[idx], result);
313 res = g_strdup (rtsp_results[idx]);
320 * gst_rtsp_method_as_text:
321 * @method: a #GstRTSPMethod
323 * Convert @method to a string.
325 * Returns: a string representation of @method.
328 gst_rtsp_method_as_text (GstRTSPMethod method)
332 if (method == GST_RTSP_INVALID)
336 while ((method & 1) == 0) {
340 return rtsp_methods[i];
344 * gst_rtsp_version_as_text:
345 * @version: a #GstRTSPVersion
347 * Convert @version to a string.
349 * Returns: a string representation of @version.
352 gst_rtsp_version_as_text (GstRTSPVersion version)
355 case GST_RTSP_VERSION_1_0:
358 case GST_RTSP_VERSION_1_1:
367 * gst_rtsp_header_as_text:
368 * @field: a #GstRTSPHeaderField
370 * Convert @field to a string.
372 * Returns: a string representation of @field.
375 gst_rtsp_header_as_text (GstRTSPHeaderField field)
377 if (field == GST_RTSP_HDR_INVALID)
380 return rtsp_headers[field - 1].name;
384 * gst_rtsp_status_as_text:
385 * @code: a #GstRTSPStatusCode
387 * Convert @code to a string.
389 * Returns: a string representation of @code.
392 gst_rtsp_status_as_text (GstRTSPStatusCode code)
394 static GHashTable *statuses;
396 if (G_UNLIKELY (statuses == NULL))
397 statuses = rtsp_init_status ();
399 return g_hash_table_lookup (statuses, GUINT_TO_POINTER (code));
403 * gst_rtsp_find_header_field:
404 * @header: a header string
406 * Convert @header to a #GstRTSPHeaderField.
408 * Returns: a #GstRTSPHeaderField for @header or #GST_RTSP_HDR_INVALID if the
409 * header field is unknown.
412 gst_rtsp_find_header_field (const gchar * header)
416 for (idx = 0; rtsp_headers[idx].name; idx++) {
417 if (g_ascii_strcasecmp (rtsp_headers[idx].name, header) == 0) {
421 return GST_RTSP_HDR_INVALID;
425 * gst_rtsp_find_method:
428 * Convert @method to a #GstRTSPMethod.
430 * Returns: a #GstRTSPMethod for @method or #GST_RTSP_INVALID if the
434 gst_rtsp_find_method (const gchar * method)
438 for (idx = 0; rtsp_methods[idx]; idx++) {
439 if (g_ascii_strcasecmp (rtsp_methods[idx], method) == 0) {
443 return GST_RTSP_INVALID;
447 * gst_rtsp_options_as_text:
448 * @options: one or more #GstRTSPMethod
450 * Convert @options to a string.
452 * Returns: a new string of @options. g_free() after usage.
457 gst_rtsp_options_as_text (GstRTSPMethod options)
461 str = g_string_new ("");
463 if (options & GST_RTSP_OPTIONS)
464 g_string_append (str, "OPTIONS, ");
465 if (options & GST_RTSP_DESCRIBE)
466 g_string_append (str, "DESCRIBE, ");
467 if (options & GST_RTSP_ANNOUNCE)
468 g_string_append (str, "ANNOUNCE, ");
469 if (options & GST_RTSP_GET_PARAMETER)
470 g_string_append (str, "GET_PARAMETER, ");
471 if (options & GST_RTSP_PAUSE)
472 g_string_append (str, "PAUSE, ");
473 if (options & GST_RTSP_PLAY)
474 g_string_append (str, "PLAY, ");
475 if (options & GST_RTSP_RECORD)
476 g_string_append (str, "RECORD, ");
477 if (options & GST_RTSP_REDIRECT)
478 g_string_append (str, "REDIRECT, ");
479 if (options & GST_RTSP_SETUP)
480 g_string_append (str, "SETUP, ");
481 if (options & GST_RTSP_SET_PARAMETER)
482 g_string_append (str, "SET_PARAMETER, ");
483 if (options & GST_RTSP_TEARDOWN)
484 g_string_append (str, "TEARDOWN, ");
486 /* remove trailing ", " if there is one */
488 str = g_string_truncate (str, str->len - 2);
490 return g_string_free (str, FALSE);
494 * gst_rtsp_header_allow_multiple:
495 * @field: a #GstRTSPHeaderField
497 * Check whether @field may appear multiple times in a message.
499 * Returns: %TRUE if multiple headers are allowed.
504 gst_rtsp_header_allow_multiple (GstRTSPHeaderField field)
506 if (field == GST_RTSP_HDR_INVALID)
509 return rtsp_headers[field - 1].multiple;