2003-01-16 21:22:06 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
* 2000 Wim Taymans <wtay@chello.be>
|
|
|
|
*
|
2003-01-16 22:03:39 +00:00
|
|
|
* gsturi.c: register URI handlers
|
2003-01-16 21:22:06 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2005-10-15 16:01:57 +00:00
|
|
|
|
2005-08-31 14:08:45 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gsturihandler
|
2005-11-09 15:34:46 +00:00
|
|
|
* @short_description: Interface to ease URI handling in plugins.
|
2005-08-31 14:08:45 +00:00
|
|
|
*
|
2005-11-09 15:34:46 +00:00
|
|
|
* The URIHandler is an interface that is implemented by Source and Sink
|
|
|
|
* #GstElement to simplify then handling of URI.
|
|
|
|
*
|
|
|
|
* An application can use the following functions to quickly get an element
|
2006-01-27 22:34:51 +00:00
|
|
|
* that handles the given URI for reading or writing
|
|
|
|
* (gst_element_make_from_uri()).
|
2005-11-09 15:34:46 +00:00
|
|
|
*
|
2006-01-27 22:34:51 +00:00
|
|
|
* Source and Sink plugins should implement this interface when possible.
|
2005-11-09 15:34:46 +00:00
|
|
|
*
|
|
|
|
* Last reviewed on 2005-11-09 (0.9.4)
|
2005-08-31 14:08:45 +00:00
|
|
|
*/
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2004-05-07 02:36:28 +00:00
|
|
|
#include "gst_private.h"
|
2003-01-16 21:22:06 +00:00
|
|
|
#include "gsturi.h"
|
2003-06-29 14:05:49 +00:00
|
|
|
#include "gstinfo.h"
|
2003-11-24 03:21:54 +00:00
|
|
|
#include "gstmarshal.h"
|
2005-09-15 00:13:26 +00:00
|
|
|
#include "gstregistry.h"
|
2003-11-24 03:21:54 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_uri_handler_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_uri_handler_debug
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void gst_uri_handler_base_init (gpointer g_class);
|
2003-01-16 21:22:06 +00:00
|
|
|
|
|
|
|
GType
|
|
|
|
gst_uri_handler_get_type (void)
|
|
|
|
{
|
2009-04-04 08:20:36 +00:00
|
|
|
static volatile gsize urihandler_type = 0;
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2009-04-04 08:20:36 +00:00
|
|
|
if (g_once_init_enter (&urihandler_type)) {
|
|
|
|
GType _type;
|
2003-01-16 22:03:39 +00:00
|
|
|
static const GTypeInfo urihandler_info = {
|
2003-11-24 03:21:54 +00:00
|
|
|
sizeof (GstURIHandlerInterface),
|
|
|
|
gst_uri_handler_base_init,
|
2003-01-16 21:22:06 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
2003-11-24 03:21:54 +00:00
|
|
|
0,
|
|
|
|
NULL,
|
2003-01-16 21:22:06 +00:00
|
|
|
NULL
|
|
|
|
};
|
2004-03-15 19:27:17 +00:00
|
|
|
|
2009-04-04 08:20:36 +00:00
|
|
|
_type = g_type_register_static (G_TYPE_INTERFACE,
|
2004-03-15 19:27:17 +00:00
|
|
|
"GstURIHandler", &urihandler_info, 0);
|
2003-11-24 03:21:54 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_uri_handler_debug, "GST_URI", GST_DEBUG_BOLD,
|
2004-03-15 19:27:17 +00:00
|
|
|
"handling of URIs");
|
2009-04-04 08:20:36 +00:00
|
|
|
g_once_init_leave (&urihandler_type, _type);
|
2003-01-16 21:22:06 +00:00
|
|
|
}
|
2003-01-16 22:03:39 +00:00
|
|
|
return urihandler_type;
|
2003-01-16 21:22:06 +00:00
|
|
|
}
|
2009-04-04 08:20:36 +00:00
|
|
|
|
2003-01-16 21:22:06 +00:00
|
|
|
static void
|
2003-11-24 03:21:54 +00:00
|
|
|
gst_uri_handler_base_init (gpointer g_class)
|
2003-01-16 21:22:06 +00:00
|
|
|
{
|
2003-11-24 03:21:54 +00:00
|
|
|
static gboolean initialized = FALSE;
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2007-06-27 10:12:14 +00:00
|
|
|
if (G_UNLIKELY (!initialized)) {
|
2005-11-09 15:34:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GstURIHandler::new-uri:
|
|
|
|
* @handler: The #GstURIHandler which emitted the signal
|
|
|
|
* @uri: The new URI, or NULL if the URI was removed
|
|
|
|
*
|
|
|
|
* The URI of the given @handler has changed.
|
|
|
|
*/
|
|
|
|
|
2004-03-04 20:06:02 +00:00
|
|
|
g_signal_new ("new-uri", GST_TYPE_URI_HANDLER, G_SIGNAL_RUN_LAST,
|
2004-03-15 19:27:17 +00:00
|
|
|
G_STRUCT_OFFSET (GstURIHandlerInterface, new_uri), NULL, NULL,
|
|
|
|
gst_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
|
2003-11-24 03:21:54 +00:00
|
|
|
initialized = TRUE;
|
|
|
|
}
|
2003-01-16 21:22:06 +00:00
|
|
|
}
|
|
|
|
|
2004-10-11 09:44:05 +00:00
|
|
|
static const guchar acceptable[96] = { /* X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 XA XB XC XD XE XF */
|
|
|
|
0x00, 0x3F, 0x20, 0x20, 0x20, 0x00, 0x2C, 0x3F, 0x3F, 0x3F, 0x3F, 0x22, 0x20, 0x3F, 0x3F, 0x1C, /* 2X !"#$%&'()*+,-./ */
|
|
|
|
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x38, 0x20, 0x20, 0x2C, 0x20, 0x2C, /* 3X 0123456789:;<=>? */
|
|
|
|
0x30, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, /* 4X @ABCDEFGHIJKLMNO */
|
|
|
|
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x20, 0x20, 0x20, 0x20, 0x3F, /* 5X PQRSTUVWXYZ[\]^_ */
|
|
|
|
0x20, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, /* 6X `abcdefghijklmno */
|
|
|
|
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x20, 0x20, 0x20, 0x3F, 0x20 /* 7X pqrstuvwxyz{|}~DEL */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
UNSAFE_ALL = 0x1, /* Escape all unsafe characters */
|
|
|
|
UNSAFE_ALLOW_PLUS = 0x2, /* Allows '+' */
|
|
|
|
UNSAFE_PATH = 0x4, /* Allows '/' and '?' and '&' and '=' */
|
|
|
|
UNSAFE_DOS_PATH = 0x8, /* Allows '/' and '?' and '&' and '=' and ':' */
|
|
|
|
UNSAFE_HOST = 0x10, /* Allows '/' and ':' and '@' */
|
|
|
|
UNSAFE_SLASHES = 0x20 /* Allows all characters except for '/' and '%' */
|
|
|
|
} UnsafeCharacterSet;
|
|
|
|
|
|
|
|
#define HEX_ESCAPE '%'
|
|
|
|
|
|
|
|
/* Escape undesirable characters using %
|
|
|
|
* -------------------------------------
|
|
|
|
*
|
|
|
|
* This function takes a pointer to a string in which
|
|
|
|
* some characters may be unacceptable unescaped.
|
|
|
|
* It returns a string which has these characters
|
|
|
|
* represented by a '%' character followed by two hex digits.
|
|
|
|
*
|
|
|
|
* This routine returns a g_malloced string.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const gchar hex[16] = "0123456789ABCDEF";
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
escape_string_internal (const gchar * string, UnsafeCharacterSet mask)
|
|
|
|
{
|
|
|
|
#define ACCEPTABLE_CHAR(a) ((a)>=32 && (a)<128 && (acceptable[(a)-32] & use_mask))
|
|
|
|
|
|
|
|
const gchar *p;
|
|
|
|
gchar *q;
|
|
|
|
gchar *result;
|
|
|
|
guchar c;
|
|
|
|
gint unacceptable;
|
|
|
|
UnsafeCharacterSet use_mask;
|
|
|
|
|
|
|
|
g_return_val_if_fail (mask == UNSAFE_ALL
|
|
|
|
|| mask == UNSAFE_ALLOW_PLUS
|
|
|
|
|| mask == UNSAFE_PATH
|
|
|
|
|| mask == UNSAFE_DOS_PATH
|
|
|
|
|| mask == UNSAFE_HOST || mask == UNSAFE_SLASHES, NULL);
|
|
|
|
|
|
|
|
if (string == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
unacceptable = 0;
|
|
|
|
use_mask = mask;
|
|
|
|
for (p = string; *p != '\0'; p++) {
|
|
|
|
c = *p;
|
|
|
|
if (!ACCEPTABLE_CHAR (c)) {
|
|
|
|
unacceptable++;
|
|
|
|
}
|
|
|
|
if ((use_mask == UNSAFE_HOST) && (unacceptable || (c == '/'))) {
|
|
|
|
/* when escaping a host, if we hit something that needs to be escaped, or we finally
|
|
|
|
* hit a path separator, revert to path mode (the host segment of the url is over).
|
|
|
|
*/
|
|
|
|
use_mask = UNSAFE_PATH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = g_malloc (p - string + unacceptable * 2 + 1);
|
|
|
|
|
|
|
|
use_mask = mask;
|
|
|
|
for (q = result, p = string; *p != '\0'; p++) {
|
|
|
|
c = *p;
|
|
|
|
|
|
|
|
if (!ACCEPTABLE_CHAR (c)) {
|
|
|
|
*q++ = HEX_ESCAPE; /* means hex coming */
|
|
|
|
*q++ = hex[c >> 4];
|
|
|
|
*q++ = hex[c & 15];
|
|
|
|
} else {
|
|
|
|
*q++ = c;
|
|
|
|
}
|
|
|
|
if ((use_mask == UNSAFE_HOST) && (!ACCEPTABLE_CHAR (c) || (c == '/'))) {
|
|
|
|
use_mask = UNSAFE_PATH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*q = '\0';
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* escape_string:
|
|
|
|
* @string: string to be escaped
|
|
|
|
*
|
2005-10-15 15:30:24 +00:00
|
|
|
* Escapes @string, replacing any and all special characters
|
2004-10-11 09:44:05 +00:00
|
|
|
* with equivalent escape sequences.
|
|
|
|
*
|
|
|
|
* Return value: a newly allocated string equivalent to @string
|
|
|
|
* but with all special characters escaped
|
|
|
|
**/
|
2005-11-09 15:34:46 +00:00
|
|
|
static gchar *
|
2004-10-11 09:44:05 +00:00
|
|
|
escape_string (const gchar * string)
|
|
|
|
{
|
|
|
|
return escape_string_internal (string, UNSAFE_ALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hex_to_int (gchar c)
|
|
|
|
{
|
|
|
|
return c >= '0' && c <= '9' ? c - '0'
|
|
|
|
: c >= 'A' && c <= 'F' ? c - 'A' + 10
|
|
|
|
: c >= 'a' && c <= 'f' ? c - 'a' + 10 : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
unescape_character (const char *scanner)
|
|
|
|
{
|
|
|
|
int first_digit;
|
|
|
|
int second_digit;
|
|
|
|
|
|
|
|
first_digit = hex_to_int (*scanner++);
|
|
|
|
if (first_digit < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-04-03 09:56:48 +00:00
|
|
|
second_digit = hex_to_int (*scanner);
|
2004-10-11 09:44:05 +00:00
|
|
|
if (second_digit < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (first_digit << 4) | second_digit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* unescape_string:
|
|
|
|
* @escaped_string: an escaped URI, path, or other string
|
|
|
|
* @illegal_characters: a string containing a sequence of characters
|
|
|
|
* considered "illegal", '\0' is automatically in this list.
|
|
|
|
*
|
|
|
|
* Decodes escaped characters (i.e. PERCENTxx sequences) in @escaped_string.
|
2005-10-15 15:30:24 +00:00
|
|
|
* Characters are encoded in PERCENTxy form, where xy is the ASCII hex code
|
2004-10-11 09:44:05 +00:00
|
|
|
* for character 16x+y.
|
2005-10-15 15:30:24 +00:00
|
|
|
*
|
|
|
|
* Return value: a newly allocated string with the unescaped equivalents,
|
|
|
|
* or %NULL if @escaped_string contained one of the characters
|
2004-10-11 09:44:05 +00:00
|
|
|
* in @illegal_characters.
|
|
|
|
**/
|
|
|
|
static char *
|
|
|
|
unescape_string (const gchar * escaped_string, const gchar * illegal_characters)
|
|
|
|
{
|
|
|
|
const gchar *in;
|
|
|
|
gchar *out, *result;
|
|
|
|
gint character;
|
|
|
|
|
|
|
|
if (escaped_string == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = g_malloc (strlen (escaped_string) + 1);
|
|
|
|
|
|
|
|
out = result;
|
|
|
|
for (in = escaped_string; *in != '\0'; in++) {
|
|
|
|
character = *in;
|
|
|
|
if (*in == HEX_ESCAPE) {
|
|
|
|
character = unescape_character (in + 1);
|
|
|
|
|
|
|
|
/* Check for an illegal character. We consider '\0' illegal here. */
|
|
|
|
if (character <= 0
|
|
|
|
|| (illegal_characters != NULL
|
|
|
|
&& strchr (illegal_characters, (char) character) != NULL)) {
|
|
|
|
g_free (result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
in += 2;
|
|
|
|
}
|
|
|
|
*out++ = (char) character;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out = '\0';
|
2008-03-03 18:42:04 +00:00
|
|
|
g_assert ((gsize) (out - result) <= strlen (escaped_string));
|
2004-10-11 09:44:05 +00:00
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-16 21:22:06 +00:00
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_uri_protocol_check_internal (const gchar * uri, gchar ** endptr)
|
2003-01-16 21:22:06 +00:00
|
|
|
{
|
2003-11-24 03:21:54 +00:00
|
|
|
gchar *check = (gchar *) uri;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
g_assert (uri != NULL);
|
|
|
|
g_assert (endptr != NULL);
|
|
|
|
|
2004-02-02 21:08:52 +00:00
|
|
|
if (g_ascii_isalpha (*check)) {
|
2003-11-24 03:21:54 +00:00
|
|
|
check++;
|
2008-04-19 15:36:20 +00:00
|
|
|
while (g_ascii_isalnum (*check) || *check == '+'
|
|
|
|
|| *check == '-' || *check == '.')
|
2004-03-13 15:27:01 +00:00
|
|
|
check++;
|
2003-11-24 03:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*endptr = check;
|
2003-01-16 21:22:06 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
/**
|
|
|
|
* gst_uri_protocol_is_valid:
|
2005-11-09 15:34:46 +00:00
|
|
|
* @protocol: A string
|
2003-11-24 03:21:54 +00:00
|
|
|
*
|
|
|
|
* Tests if the given string is a valid protocol identifier. Protocols
|
2008-04-19 15:36:20 +00:00
|
|
|
* must consist of alphanumeric characters, '+', '-' and '.' and must
|
|
|
|
* start with a alphabetic character. See RFC 3986 Section 3.1.
|
2003-11-24 03:21:54 +00:00
|
|
|
*
|
2005-11-09 15:34:46 +00:00
|
|
|
* Returns: TRUE if the string is a valid protocol identifier, FALSE otherwise.
|
2003-11-24 03:21:54 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_uri_protocol_is_valid (const gchar * protocol)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
|
|
|
gchar *endptr;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
g_return_val_if_fail (protocol != NULL, FALSE);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
gst_uri_protocol_check_internal (protocol, &endptr);
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
return *endptr == '\0' && endptr != protocol;
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-16 21:22:06 +00:00
|
|
|
/**
|
2003-11-24 03:21:54 +00:00
|
|
|
* gst_uri_is_valid:
|
2005-11-09 15:34:46 +00:00
|
|
|
* @uri: A URI string
|
2003-01-16 21:22:06 +00:00
|
|
|
*
|
2003-11-24 03:21:54 +00:00
|
|
|
* Tests if the given string is a valid URI identifier. URIs start with a valid
|
2008-07-31 17:16:50 +00:00
|
|
|
* scheme followed by ":" and maybe a string identifying the location.
|
2003-01-16 21:22:06 +00:00
|
|
|
*
|
2003-11-24 03:21:54 +00:00
|
|
|
* Returns: TRUE if the string is a valid URI
|
2003-01-16 21:22:06 +00:00
|
|
|
*/
|
2003-11-24 03:21:54 +00:00
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_uri_is_valid (const gchar * uri)
|
2003-01-16 21:22:06 +00:00
|
|
|
{
|
2003-11-24 03:21:54 +00:00
|
|
|
gchar *endptr;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
g_return_val_if_fail (uri != NULL, FALSE);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
gst_uri_protocol_check_internal (uri, &endptr);
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2008-07-31 17:16:50 +00:00
|
|
|
return *endptr == ':';
|
2003-11-24 03:21:54 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
/**
|
|
|
|
* gst_uri_get_protocol:
|
2005-11-09 15:34:46 +00:00
|
|
|
* @uri: A URI string
|
2003-11-24 03:21:54 +00:00
|
|
|
*
|
|
|
|
* Extracts the protocol out of a given valid URI. The returned string must be
|
|
|
|
* freed using g_free().
|
|
|
|
*
|
|
|
|
* Returns: The protocol for this URI.
|
|
|
|
*/
|
|
|
|
gchar *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_uri_get_protocol (const gchar * uri)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
|
|
|
gchar *colon;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-16 21:22:06 +00:00
|
|
|
g_return_val_if_fail (uri != NULL, NULL);
|
2003-11-24 03:21:54 +00:00
|
|
|
g_return_val_if_fail (gst_uri_is_valid (uri), NULL);
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2008-07-31 17:16:50 +00:00
|
|
|
colon = strstr (uri, ":");
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2008-04-20 16:32:03 +00:00
|
|
|
return g_ascii_strdown (uri, colon - uri);
|
2003-01-16 21:22:06 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2006-03-09 12:08:54 +00:00
|
|
|
/**
|
|
|
|
* gst_uri_has_protocol:
|
|
|
|
* @uri: an URI string
|
|
|
|
* @protocol: a protocol string (e.g. "http")
|
|
|
|
*
|
2006-11-06 15:18:57 +00:00
|
|
|
* Checks if the protocol of a given valid URI matches @protocol.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the protocol matches.
|
2006-03-09 12:08:54 +00:00
|
|
|
*
|
|
|
|
* Since: 0.10.4
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_uri_has_protocol (const gchar * uri, const gchar * protocol)
|
|
|
|
{
|
|
|
|
gchar *colon;
|
|
|
|
|
|
|
|
g_return_val_if_fail (uri != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (protocol != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (gst_uri_is_valid (uri), FALSE);
|
|
|
|
|
2008-07-31 17:16:50 +00:00
|
|
|
colon = strstr (uri, ":");
|
2006-03-09 12:08:54 +00:00
|
|
|
|
|
|
|
if (colon == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2008-04-19 15:36:20 +00:00
|
|
|
return (g_ascii_strncasecmp (uri, protocol, (gsize) (colon - uri)) == 0);
|
2006-03-09 12:08:54 +00:00
|
|
|
}
|
|
|
|
|
2003-01-16 21:22:06 +00:00
|
|
|
/**
|
2003-11-24 03:21:54 +00:00
|
|
|
* gst_uri_get_location:
|
2005-11-09 15:34:46 +00:00
|
|
|
* @uri: A URI string
|
2003-01-16 21:22:06 +00:00
|
|
|
*
|
2007-09-12 12:36:51 +00:00
|
|
|
* Extracts the location out of a given valid URI, ie. the protocol and "://"
|
|
|
|
* are stripped from the URI, which means that the location returned includes
|
|
|
|
* the hostname if one is specified. The returned string must be freed using
|
2003-11-24 03:21:54 +00:00
|
|
|
* g_free().
|
2003-01-16 21:22:06 +00:00
|
|
|
*
|
2007-09-12 12:36:51 +00:00
|
|
|
* Returns: The location for this URI. Returns NULL if the URI isn't valid. If
|
|
|
|
* the URI does not contain a location, an empty string is returned.
|
2003-01-16 21:22:06 +00:00
|
|
|
*/
|
2003-11-24 03:21:54 +00:00
|
|
|
gchar *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_uri_get_location (const gchar * uri)
|
2003-01-16 21:22:06 +00:00
|
|
|
{
|
2007-09-12 12:36:51 +00:00
|
|
|
const gchar *colon;
|
|
|
|
gchar *unescaped = NULL;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
g_return_val_if_fail (uri != NULL, NULL);
|
|
|
|
g_return_val_if_fail (gst_uri_is_valid (uri), NULL);
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
colon = strstr (uri, "://");
|
2008-08-28 10:45:04 +00:00
|
|
|
if (!colon)
|
|
|
|
return NULL;
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2007-09-12 12:36:51 +00:00
|
|
|
unescaped = unescape_string (colon + 3, "/");
|
|
|
|
|
|
|
|
/* On Windows an URI might look like file:///c:/foo/bar.txt or
|
|
|
|
* file:///c|/foo/bar.txt (some Netscape versions) and we want to
|
|
|
|
* return c:/foo/bar.txt as location rather than /c:/foo/bar.txt.
|
|
|
|
* Can't use g_filename_from_uri() here because it will only handle the
|
|
|
|
* file:// protocol */
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
if (unescaped != NULL && unescaped[0] == '/' &&
|
|
|
|
g_ascii_isalpha (unescaped[1]) &&
|
|
|
|
(unescaped[2] == ':' || unescaped[2] == '|')) {
|
|
|
|
unescaped[2] = ':';
|
|
|
|
g_memmove (unescaped, unescaped + 1, strlen (unescaped + 1) + 1);
|
|
|
|
}
|
|
|
|
#endif
|
2004-10-11 09:44:05 +00:00
|
|
|
|
2007-09-12 12:36:51 +00:00
|
|
|
GST_LOG ("extracted location '%s' from URI '%s'", GST_STR_NULL (unescaped),
|
2009-06-07 21:49:01 +00:00
|
|
|
uri);
|
2004-10-11 09:44:05 +00:00
|
|
|
return unescaped;
|
2003-01-16 21:22:06 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
/**
|
|
|
|
* gst_uri_construct:
|
2005-11-09 15:34:46 +00:00
|
|
|
* @protocol: Protocol for URI
|
|
|
|
* @location: Location for URI
|
2003-11-24 03:21:54 +00:00
|
|
|
*
|
|
|
|
* Constructs a URI for a given valid protocol and location.
|
|
|
|
*
|
2005-11-09 15:34:46 +00:00
|
|
|
* Returns: a new string for this URI. Returns NULL if the given URI protocol
|
|
|
|
* is not valid, or the given location is NULL.
|
2003-01-17 16:06:23 +00:00
|
|
|
*/
|
2003-11-24 03:21:54 +00:00
|
|
|
gchar *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_uri_construct (const gchar * protocol, const gchar * location)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
2008-04-19 15:36:20 +00:00
|
|
|
char *escaped, *proto_lowercase;
|
2004-10-11 09:44:05 +00:00
|
|
|
char *retval;
|
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
g_return_val_if_fail (gst_uri_protocol_is_valid (protocol), NULL);
|
|
|
|
g_return_val_if_fail (location != NULL, NULL);
|
|
|
|
|
2008-04-19 15:36:20 +00:00
|
|
|
proto_lowercase = g_ascii_strdown (protocol, -1);
|
2004-10-11 09:44:05 +00:00
|
|
|
escaped = escape_string (location);
|
2008-04-19 15:36:20 +00:00
|
|
|
retval = g_strdup_printf ("%s://%s", proto_lowercase, escaped);
|
2004-10-11 09:44:05 +00:00
|
|
|
g_free (escaped);
|
2008-04-19 15:36:20 +00:00
|
|
|
g_free (proto_lowercase);
|
2004-10-11 09:44:05 +00:00
|
|
|
|
|
|
|
return retval;
|
2003-11-24 03:21:54 +00:00
|
|
|
}
|
2004-07-26 16:34:35 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstURIType type;
|
2007-04-27 08:30:59 +00:00
|
|
|
const gchar *protocol;
|
2004-03-15 19:27:17 +00:00
|
|
|
}
|
|
|
|
SearchEntry;
|
2004-07-26 16:34:35 +00:00
|
|
|
|
2003-01-17 16:06:23 +00:00
|
|
|
static gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
search_by_entry (GstPluginFeature * feature, gpointer search_entry)
|
2003-01-17 16:06:23 +00:00
|
|
|
{
|
2003-11-24 03:21:54 +00:00
|
|
|
gchar **protocols;
|
|
|
|
GstElementFactory *factory;
|
|
|
|
SearchEntry *entry = (SearchEntry *) search_entry;
|
|
|
|
|
|
|
|
if (!GST_IS_ELEMENT_FACTORY (feature))
|
2003-01-17 16:06:23 +00:00
|
|
|
return FALSE;
|
2009-10-22 11:13:56 +00:00
|
|
|
factory = GST_ELEMENT_FACTORY_CAST (feature);
|
2003-11-24 03:21:54 +00:00
|
|
|
|
2009-10-22 11:13:56 +00:00
|
|
|
if (factory->uri_type != entry->type)
|
2003-11-24 03:21:54 +00:00
|
|
|
return FALSE;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
protocols = gst_element_factory_get_uri_protocols (factory);
|
2006-09-25 11:16:37 +00:00
|
|
|
|
|
|
|
if (protocols == NULL) {
|
|
|
|
g_warning ("Factory '%s' implements GstUriHandler interface but returned "
|
|
|
|
"no supported protocols!", gst_plugin_feature_get_name (feature));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
while (*protocols != NULL) {
|
2007-05-11 14:28:55 +00:00
|
|
|
if (g_ascii_strcasecmp (*protocols, entry->protocol) == 0)
|
2003-11-24 03:21:54 +00:00
|
|
|
return TRUE;
|
|
|
|
protocols++;
|
2003-01-17 16:06:23 +00:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
static gint
|
2009-10-22 11:15:15 +00:00
|
|
|
sort_by_rank (GstPluginFeature * first, GstPluginFeature * second)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
return gst_plugin_feature_get_rank (second) -
|
|
|
|
gst_plugin_feature_get_rank (first);
|
2003-11-24 03:21:54 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2007-04-27 08:30:59 +00:00
|
|
|
static GList *
|
|
|
|
get_element_factories_from_uri_protocol (const GstURIType type,
|
|
|
|
const gchar * protocol)
|
|
|
|
{
|
|
|
|
GList *possibilities;
|
|
|
|
SearchEntry entry;
|
|
|
|
|
|
|
|
g_return_val_if_fail (protocol, NULL);
|
|
|
|
|
|
|
|
entry.type = type;
|
|
|
|
entry.protocol = protocol;
|
|
|
|
possibilities = gst_registry_feature_filter (gst_registry_get_default (),
|
|
|
|
search_by_entry, FALSE, &entry);
|
|
|
|
|
|
|
|
return possibilities;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_uri_protocol_is_supported:
|
2007-04-28 11:29:54 +00:00
|
|
|
* @type: Whether to check for a source or a sink
|
|
|
|
* @protocol: Protocol that should be checked for (e.g. "http" or "smb")
|
2007-04-27 08:30:59 +00:00
|
|
|
*
|
2007-04-28 11:29:54 +00:00
|
|
|
* Checks if an element exists that supports the given URI protocol. Note
|
|
|
|
* that a positive return value does not imply that a subsequent call to
|
|
|
|
* gst_element_make_from_uri() is guaranteed to work.
|
2007-04-27 08:30:59 +00:00
|
|
|
*
|
|
|
|
* Returns: TRUE
|
|
|
|
*
|
|
|
|
* Since: 0.10.13
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_uri_protocol_is_supported (const GstURIType type, const gchar * protocol)
|
|
|
|
{
|
|
|
|
GList *possibilities;
|
|
|
|
|
|
|
|
g_return_val_if_fail (protocol, FALSE);
|
|
|
|
|
|
|
|
possibilities = get_element_factories_from_uri_protocol (type, protocol);
|
|
|
|
|
|
|
|
if (possibilities) {
|
|
|
|
g_list_free (possibilities);
|
|
|
|
return TRUE;
|
|
|
|
} else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-05-06 22:10:29 +00:00
|
|
|
/**
|
2003-11-24 03:21:54 +00:00
|
|
|
* gst_element_make_from_uri:
|
2007-04-28 11:29:54 +00:00
|
|
|
* @type: Whether to create a source or a sink
|
2005-11-09 15:34:46 +00:00
|
|
|
* @uri: URI to create an element for
|
|
|
|
* @elementname: Name of created element, can be NULL.
|
2003-05-06 22:10:29 +00:00
|
|
|
*
|
2005-10-15 15:30:24 +00:00
|
|
|
* Creates an element for handling the given URI.
|
|
|
|
*
|
2003-11-24 03:21:54 +00:00
|
|
|
* Returns: a new element or NULL if none could be created
|
2003-05-06 22:10:29 +00:00
|
|
|
*/
|
2003-11-24 03:21:54 +00:00
|
|
|
GstElement *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_element_make_from_uri (const GstURIType type, const gchar * uri,
|
|
|
|
const gchar * elementname)
|
2003-04-14 18:53:03 +00:00
|
|
|
{
|
2003-11-24 03:21:54 +00:00
|
|
|
GList *possibilities, *walk;
|
2007-04-27 08:30:59 +00:00
|
|
|
gchar *protocol;
|
2003-11-24 03:21:54 +00:00
|
|
|
GstElement *ret = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_URI_TYPE_IS_VALID (type), NULL);
|
|
|
|
g_return_val_if_fail (gst_uri_is_valid (uri), NULL);
|
|
|
|
|
2007-04-27 08:30:59 +00:00
|
|
|
protocol = gst_uri_get_protocol (uri);
|
|
|
|
possibilities = get_element_factories_from_uri_protocol (type, protocol);
|
|
|
|
g_free (protocol);
|
2003-11-24 03:21:54 +00:00
|
|
|
|
|
|
|
if (!possibilities) {
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_DEBUG ("No %s for URI '%s'", type == GST_URI_SINK ? "sink" : "source",
|
2004-03-15 19:27:17 +00:00
|
|
|
uri);
|
2003-11-24 03:21:54 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2009-10-22 11:15:15 +00:00
|
|
|
possibilities = g_list_sort (possibilities, (GCompareFunc) sort_by_rank);
|
2003-11-24 03:21:54 +00:00
|
|
|
walk = possibilities;
|
|
|
|
while (walk) {
|
2009-10-22 11:13:56 +00:00
|
|
|
if ((ret =
|
|
|
|
gst_element_factory_create (GST_ELEMENT_FACTORY_CAST (walk->data),
|
2004-03-15 19:27:17 +00:00
|
|
|
elementname)) != NULL) {
|
2003-11-24 03:21:54 +00:00
|
|
|
GstURIHandler *handler = GST_URI_HANDLER (ret);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
if (gst_uri_handler_set_uri (handler, uri))
|
2004-03-15 19:27:17 +00:00
|
|
|
break;
|
2005-06-28 09:59:01 +00:00
|
|
|
gst_object_unref (ret);
|
2003-11-24 03:21:54 +00:00
|
|
|
ret = NULL;
|
2003-04-14 18:53:03 +00:00
|
|
|
}
|
2005-06-20 11:32:14 +00:00
|
|
|
walk = walk->next;
|
2003-04-14 18:53:03 +00:00
|
|
|
}
|
2007-05-11 14:46:10 +00:00
|
|
|
gst_plugin_feature_list_free (possibilities);
|
2003-05-06 22:10:29 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
GST_LOG_OBJECT (ret, "created %s for URL '%s'",
|
|
|
|
type == GST_URI_SINK ? "sink" : "source", uri);
|
2003-11-24 03:21:54 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-16 22:03:39 +00:00
|
|
|
/**
|
2003-11-24 03:21:54 +00:00
|
|
|
* gst_uri_handler_get_uri_type:
|
2005-11-09 15:34:46 +00:00
|
|
|
* @handler: A #GstURIHandler.
|
2003-01-16 22:03:39 +00:00
|
|
|
*
|
2005-11-09 15:34:46 +00:00
|
|
|
* Gets the type of the given URI handler
|
2003-01-16 22:03:39 +00:00
|
|
|
*
|
2005-11-09 15:34:46 +00:00
|
|
|
* Returns: the #GstURIType of the URI handler.
|
|
|
|
* Returns #GST_URI_UNKNOWN if the @handler isn't implemented correctly.
|
2003-01-16 22:03:39 +00:00
|
|
|
*/
|
2003-11-24 03:21:54 +00:00
|
|
|
guint
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_uri_handler_get_uri_type (GstURIHandler * handler)
|
2003-01-16 21:22:06 +00:00
|
|
|
{
|
2003-11-24 03:21:54 +00:00
|
|
|
GstURIHandlerInterface *iface;
|
|
|
|
guint ret;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
g_return_val_if_fail (GST_IS_URI_HANDLER (handler), GST_URI_UNKNOWN);
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
iface = GST_URI_HANDLER_GET_INTERFACE (handler);
|
|
|
|
g_return_val_if_fail (iface != NULL, GST_URI_UNKNOWN);
|
2009-05-07 07:28:15 +00:00
|
|
|
g_return_val_if_fail (iface->get_type != NULL
|
|
|
|
|| iface->get_type_full != NULL, GST_URI_UNKNOWN);
|
|
|
|
|
|
|
|
if (iface->get_type != NULL)
|
|
|
|
ret = iface->get_type ();
|
|
|
|
else
|
|
|
|
ret = iface->get_type_full (G_OBJECT_TYPE (handler));
|
2003-11-24 03:21:54 +00:00
|
|
|
g_return_val_if_fail (GST_URI_TYPE_IS_VALID (ret), GST_URI_UNKNOWN);
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
return ret;
|
2003-01-16 21:22:06 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-16 22:03:39 +00:00
|
|
|
/**
|
2003-11-24 03:21:54 +00:00
|
|
|
* gst_uri_handler_get_protocols:
|
2005-11-09 15:34:46 +00:00
|
|
|
* @handler: A #GstURIHandler.
|
2003-01-16 22:03:39 +00:00
|
|
|
*
|
2005-11-09 15:34:46 +00:00
|
|
|
* Gets the list of protocols supported by @handler. This list may not be
|
2003-11-24 03:21:54 +00:00
|
|
|
* modified.
|
2003-01-16 22:03:39 +00:00
|
|
|
*
|
2005-11-09 15:34:46 +00:00
|
|
|
* Returns: the supported protocols.
|
|
|
|
* Returns NULL if the @handler isn't implemented properly, or the @handler
|
|
|
|
* doesn't support any protocols.
|
2003-01-16 22:03:39 +00:00
|
|
|
*/
|
2003-11-24 03:21:54 +00:00
|
|
|
gchar **
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_uri_handler_get_protocols (GstURIHandler * handler)
|
2003-01-16 21:22:06 +00:00
|
|
|
{
|
2003-11-24 03:21:54 +00:00
|
|
|
GstURIHandlerInterface *iface;
|
|
|
|
gchar **ret;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
g_return_val_if_fail (GST_IS_URI_HANDLER (handler), NULL);
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
iface = GST_URI_HANDLER_GET_INTERFACE (handler);
|
|
|
|
g_return_val_if_fail (iface != NULL, NULL);
|
2008-02-29 14:23:17 +00:00
|
|
|
g_return_val_if_fail (iface->get_protocols != NULL ||
|
|
|
|
iface->get_protocols_full != NULL, NULL);
|
|
|
|
|
|
|
|
if (iface->get_protocols != NULL) {
|
|
|
|
ret = iface->get_protocols ();
|
|
|
|
} else {
|
|
|
|
ret = iface->get_protocols_full (G_OBJECT_TYPE (handler));
|
|
|
|
}
|
2003-11-24 03:21:54 +00:00
|
|
|
g_return_val_if_fail (ret != NULL, NULL);
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
return ret;
|
2003-01-16 21:22:06 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-01-16 22:03:39 +00:00
|
|
|
/**
|
2003-11-24 03:21:54 +00:00
|
|
|
* gst_uri_handler_get_uri:
|
2005-11-09 15:34:46 +00:00
|
|
|
* @handler: A #GstURIHandler
|
2003-01-16 22:03:39 +00:00
|
|
|
*
|
2005-11-09 15:34:46 +00:00
|
|
|
* Gets the currently handled URI.
|
2003-01-16 22:03:39 +00:00
|
|
|
*
|
2006-07-05 18:17:01 +00:00
|
|
|
* Returns: the URI currently handled by the @handler.
|
|
|
|
* Returns NULL if there are no URI currently handled. The returned
|
|
|
|
* string must not be modified or freed.
|
2003-01-16 22:03:39 +00:00
|
|
|
*/
|
2003-11-24 03:21:54 +00:00
|
|
|
G_CONST_RETURN gchar *
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_uri_handler_get_uri (GstURIHandler * handler)
|
2003-01-16 21:22:06 +00:00
|
|
|
{
|
2003-11-24 03:21:54 +00:00
|
|
|
GstURIHandlerInterface *iface;
|
|
|
|
const gchar *ret;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
g_return_val_if_fail (GST_IS_URI_HANDLER (handler), NULL);
|
|
|
|
|
|
|
|
iface = GST_URI_HANDLER_GET_INTERFACE (handler);
|
|
|
|
g_return_val_if_fail (iface != NULL, NULL);
|
|
|
|
g_return_val_if_fail (iface->get_uri != NULL, NULL);
|
|
|
|
ret = iface->get_uri (handler);
|
|
|
|
if (ret != NULL)
|
|
|
|
g_return_val_if_fail (gst_uri_is_valid (ret), NULL);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
return ret;
|
2003-01-16 21:22:06 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
/**
|
|
|
|
* gst_uri_handler_set_uri:
|
2005-11-09 15:34:46 +00:00
|
|
|
* @handler: A #GstURIHandler
|
2003-11-24 03:21:54 +00:00
|
|
|
* @uri: URI to set
|
|
|
|
*
|
2005-11-09 15:34:46 +00:00
|
|
|
* Tries to set the URI of the given handler.
|
2003-11-24 03:21:54 +00:00
|
|
|
*
|
2005-11-09 15:34:46 +00:00
|
|
|
* Returns: TRUE if the URI was set successfully, else FALSE.
|
2003-11-24 03:21:54 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_uri_handler_set_uri (GstURIHandler * handler, const gchar * uri)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
|
|
|
GstURIHandlerInterface *iface;
|
2008-04-19 15:36:20 +00:00
|
|
|
gboolean ret;
|
2008-07-31 17:16:50 +00:00
|
|
|
gchar *new_uri, *protocol, *location, *colon;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
g_return_val_if_fail (GST_IS_URI_HANDLER (handler), FALSE);
|
|
|
|
g_return_val_if_fail (gst_uri_is_valid (uri), FALSE);
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
iface = GST_URI_HANDLER_GET_INTERFACE (handler);
|
|
|
|
g_return_val_if_fail (iface != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (iface->set_uri != NULL, FALSE);
|
2008-04-19 15:36:20 +00:00
|
|
|
|
|
|
|
protocol = gst_uri_get_protocol (uri);
|
2008-07-31 17:16:50 +00:00
|
|
|
|
|
|
|
colon = strstr (uri, ":");
|
|
|
|
location = g_strdup (colon);
|
|
|
|
|
|
|
|
new_uri = g_strdup_printf ("%s%s", protocol, location);
|
2008-04-19 15:36:20 +00:00
|
|
|
|
|
|
|
ret = iface->set_uri (handler, uri);
|
|
|
|
|
|
|
|
g_free (new_uri);
|
|
|
|
g_free (location);
|
|
|
|
g_free (protocol);
|
|
|
|
|
|
|
|
return ret;
|
2003-11-24 03:21:54 +00:00
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
/**
|
|
|
|
* gst_uri_handler_new_uri:
|
2005-11-09 15:34:46 +00:00
|
|
|
* @handler: A #GstURIHandler
|
2003-11-24 03:21:54 +00:00
|
|
|
* @uri: new URI or NULL if it was unset
|
|
|
|
*
|
2005-11-09 15:34:46 +00:00
|
|
|
* Emits the new-uri signal for a given handler, when that handler has a new URI.
|
2003-11-24 03:21:54 +00:00
|
|
|
* This function should only be called by URI handlers themselves.
|
|
|
|
*/
|
|
|
|
void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_uri_handler_new_uri (GstURIHandler * handler, const gchar * uri)
|
2003-11-24 03:21:54 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_URI_HANDLER (handler));
|
2003-01-16 21:22:06 +00:00
|
|
|
|
2003-11-24 03:21:54 +00:00
|
|
|
g_signal_emit_by_name (handler, "new-uri", uri);
|
|
|
|
}
|