31f8f1c5ff958e39d493f5de3943249ee0540d91
[platform/upstream/gstreamer.git] / gst / gsturi.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gsturi.c: register URI handlers
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /**
24  * SECTION:gsturihandler
25  * @short_description: Interface to ease URI handling in plugins.
26  *
27  * The URIHandler is an interface that is implemented by Source and Sink 
28  * #GstElement to simplify then handling of URI.
29  *
30  * An application can use the following functions to quickly get an element
31  * that handles the given URI for reading or writing
32  * (gst_element_make_from_uri()).
33  *
34  * Source and Sink plugins should implement this interface when possible.
35  *
36  * Last reviewed on 2005-11-09 (0.9.4)
37  */
38
39 #ifdef HAVE_CONFIG_H
40 #  include "config.h"
41 #endif
42
43 #include "gst_private.h"
44 #include "gsturi.h"
45 #include "gstinfo.h"
46 #include "gstmarshal.h"
47 #include "gstregistry.h"
48
49 #include <string.h>
50
51 GST_DEBUG_CATEGORY_STATIC (gst_uri_handler_debug);
52 #define GST_CAT_DEFAULT gst_uri_handler_debug
53
54 static void gst_uri_handler_base_init (gpointer g_class);
55
56 GType
57 gst_uri_handler_get_type (void)
58 {
59   static GType urihandler_type = 0;
60
61   if (G_UNLIKELY (urihandler_type == 0)) {
62     static const GTypeInfo urihandler_info = {
63       sizeof (GstURIHandlerInterface),
64       gst_uri_handler_base_init,
65       NULL,
66       NULL,
67       NULL,
68       NULL,
69       0,
70       0,
71       NULL,
72       NULL
73     };
74
75     urihandler_type = g_type_register_static (G_TYPE_INTERFACE,
76         "GstURIHandler", &urihandler_info, 0);
77
78     GST_DEBUG_CATEGORY_INIT (gst_uri_handler_debug, "GST_URI", GST_DEBUG_BOLD,
79         "handling of URIs");
80   }
81   return urihandler_type;
82 }
83 static void
84 gst_uri_handler_base_init (gpointer g_class)
85 {
86   static gboolean initialized = FALSE;
87
88   if (G_UNLIKELY (!initialized)) {
89
90     /**
91      * GstURIHandler::new-uri:
92      * @handler: The #GstURIHandler which emitted the signal
93      * @uri: The new URI, or NULL if the URI was removed
94      *
95      * The URI of the given @handler has changed.
96      */
97
98     g_signal_new ("new-uri", GST_TYPE_URI_HANDLER, G_SIGNAL_RUN_LAST,
99         G_STRUCT_OFFSET (GstURIHandlerInterface, new_uri), NULL, NULL,
100         gst_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
101     initialized = TRUE;
102   }
103 }
104
105 static const guchar acceptable[96] = {  /* X0   X1   X2   X3   X4   X5   X6   X7   X8   X9   XA   XB   XC   XD   XE   XF */
106   0x00, 0x3F, 0x20, 0x20, 0x20, 0x00, 0x2C, 0x3F, 0x3F, 0x3F, 0x3F, 0x22, 0x20, 0x3F, 0x3F, 0x1C,       /* 2X  !"#$%&'()*+,-./   */
107   0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x38, 0x20, 0x20, 0x2C, 0x20, 0x2C,       /* 3X 0123456789:;<=>?   */
108   0x30, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,       /* 4X @ABCDEFGHIJKLMNO   */
109   0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x20, 0x20, 0x20, 0x20, 0x3F,       /* 5X PQRSTUVWXYZ[\]^_   */
110   0x20, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,       /* 6X `abcdefghijklmno   */
111   0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x20, 0x20, 0x20, 0x3F, 0x20        /* 7X pqrstuvwxyz{|}~DEL */
112 };
113
114 typedef enum
115 {
116   UNSAFE_ALL = 0x1,             /* Escape all unsafe characters   */
117   UNSAFE_ALLOW_PLUS = 0x2,      /* Allows '+'  */
118   UNSAFE_PATH = 0x4,            /* Allows '/' and '?' and '&' and '='  */
119   UNSAFE_DOS_PATH = 0x8,        /* Allows '/' and '?' and '&' and '=' and ':' */
120   UNSAFE_HOST = 0x10,           /* Allows '/' and ':' and '@' */
121   UNSAFE_SLASHES = 0x20         /* Allows all characters except for '/' and '%' */
122 } UnsafeCharacterSet;
123
124 #define HEX_ESCAPE '%'
125
126 /*  Escape undesirable characters using %
127  *  -------------------------------------
128  *
129  * This function takes a pointer to a string in which
130  * some characters may be unacceptable unescaped.
131  * It returns a string which has these characters
132  * represented by a '%' character followed by two hex digits.
133  *
134  * This routine returns a g_malloced string.
135  */
136
137 static const gchar hex[16] = "0123456789ABCDEF";
138
139 static gchar *
140 escape_string_internal (const gchar * string, UnsafeCharacterSet mask)
141 {
142 #define ACCEPTABLE_CHAR(a) ((a)>=32 && (a)<128 && (acceptable[(a)-32] & use_mask))
143
144   const gchar *p;
145   gchar *q;
146   gchar *result;
147   guchar c;
148   gint unacceptable;
149   UnsafeCharacterSet use_mask;
150
151   g_return_val_if_fail (mask == UNSAFE_ALL
152       || mask == UNSAFE_ALLOW_PLUS
153       || mask == UNSAFE_PATH
154       || mask == UNSAFE_DOS_PATH
155       || mask == UNSAFE_HOST || mask == UNSAFE_SLASHES, NULL);
156
157   if (string == NULL) {
158     return NULL;
159   }
160
161   unacceptable = 0;
162   use_mask = mask;
163   for (p = string; *p != '\0'; p++) {
164     c = *p;
165     if (!ACCEPTABLE_CHAR (c)) {
166       unacceptable++;
167     }
168     if ((use_mask == UNSAFE_HOST) && (unacceptable || (c == '/'))) {
169       /* when escaping a host, if we hit something that needs to be escaped, or we finally
170        * hit a path separator, revert to path mode (the host segment of the url is over).
171        */
172       use_mask = UNSAFE_PATH;
173     }
174   }
175
176   result = g_malloc (p - string + unacceptable * 2 + 1);
177
178   use_mask = mask;
179   for (q = result, p = string; *p != '\0'; p++) {
180     c = *p;
181
182     if (!ACCEPTABLE_CHAR (c)) {
183       *q++ = HEX_ESCAPE;        /* means hex coming */
184       *q++ = hex[c >> 4];
185       *q++ = hex[c & 15];
186     } else {
187       *q++ = c;
188     }
189     if ((use_mask == UNSAFE_HOST) && (!ACCEPTABLE_CHAR (c) || (c == '/'))) {
190       use_mask = UNSAFE_PATH;
191     }
192   }
193
194   *q = '\0';
195
196   return result;
197 }
198
199 /**
200  * escape_string:
201  * @string: string to be escaped
202  *
203  * Escapes @string, replacing any and all special characters
204  * with equivalent escape sequences.
205  *
206  * Return value: a newly allocated string equivalent to @string
207  * but with all special characters escaped
208  **/
209 static gchar *
210 escape_string (const gchar * string)
211 {
212   return escape_string_internal (string, UNSAFE_ALL);
213 }
214
215 static int
216 hex_to_int (gchar c)
217 {
218   return c >= '0' && c <= '9' ? c - '0'
219       : c >= 'A' && c <= 'F' ? c - 'A' + 10
220       : c >= 'a' && c <= 'f' ? c - 'a' + 10 : -1;
221 }
222
223 static int
224 unescape_character (const char *scanner)
225 {
226   int first_digit;
227   int second_digit;
228
229   first_digit = hex_to_int (*scanner++);
230   if (first_digit < 0) {
231     return -1;
232   }
233
234   second_digit = hex_to_int (*scanner++);
235   if (second_digit < 0) {
236     return -1;
237   }
238
239   return (first_digit << 4) | second_digit;
240 }
241
242 /**
243  * unescape_string:
244  * @escaped_string: an escaped URI, path, or other string
245  * @illegal_characters: a string containing a sequence of characters
246  * considered "illegal", '\0' is automatically in this list.
247  *
248  * Decodes escaped characters (i.e. PERCENTxx sequences) in @escaped_string.
249  * Characters are encoded in PERCENTxy form, where xy is the ASCII hex code
250  * for character 16x+y.
251  *
252  * Return value: a newly allocated string with the unescaped equivalents,
253  * or %NULL if @escaped_string contained one of the characters
254  * in @illegal_characters.
255  **/
256 static char *
257 unescape_string (const gchar * escaped_string, const gchar * illegal_characters)
258 {
259   const gchar *in;
260   gchar *out, *result;
261   gint character;
262
263   if (escaped_string == NULL) {
264     return NULL;
265   }
266
267   result = g_malloc (strlen (escaped_string) + 1);
268
269   out = result;
270   for (in = escaped_string; *in != '\0'; in++) {
271     character = *in;
272     if (*in == HEX_ESCAPE) {
273       character = unescape_character (in + 1);
274
275       /* Check for an illegal character. We consider '\0' illegal here. */
276       if (character <= 0
277           || (illegal_characters != NULL
278               && strchr (illegal_characters, (char) character) != NULL)) {
279         g_free (result);
280         return NULL;
281       }
282       in += 2;
283     }
284     *out++ = (char) character;
285   }
286
287   *out = '\0';
288   g_assert ((size_t) (out - result) <= strlen (escaped_string));
289   return result;
290
291 }
292
293
294 static void
295 gst_uri_protocol_check_internal (const gchar * uri, gchar ** endptr)
296 {
297   gchar *check = (gchar *) uri;
298
299   g_assert (uri != NULL);
300   g_assert (endptr != NULL);
301
302   if (g_ascii_isalpha (*check)) {
303     check++;
304     while (g_ascii_isalnum (*check))
305       check++;
306   }
307
308   *endptr = check;
309 }
310
311 /**
312  * gst_uri_protocol_is_valid:
313  * @protocol: A string
314  *
315  * Tests if the given string is a valid protocol identifier. Protocols
316  * must consist of alphanumeric characters and not start with a number.
317  *
318  * Returns: TRUE if the string is a valid protocol identifier, FALSE otherwise.
319  */
320 gboolean
321 gst_uri_protocol_is_valid (const gchar * protocol)
322 {
323   gchar *endptr;
324
325   g_return_val_if_fail (protocol != NULL, FALSE);
326
327   gst_uri_protocol_check_internal (protocol, &endptr);
328
329   return *endptr == '\0' && endptr != protocol;
330 }
331
332 /**
333  * gst_uri_is_valid:
334  * @uri: A URI string
335  *
336  * Tests if the given string is a valid URI identifier. URIs start with a valid
337  * protocol followed by "://" and maybe a string identifying the location.
338  *
339  * Returns: TRUE if the string is a valid URI
340  */
341 gboolean
342 gst_uri_is_valid (const gchar * uri)
343 {
344   gchar *endptr;
345
346   g_return_val_if_fail (uri != NULL, FALSE);
347
348   gst_uri_protocol_check_internal (uri, &endptr);
349
350   return (*endptr == ':' && *(endptr + 1) == '/' && *(endptr + 2) == '/');
351 }
352
353 /**
354  * gst_uri_get_protocol:
355  * @uri: A URI string
356  *
357  * Extracts the protocol out of a given valid URI. The returned string must be
358  * freed using g_free().
359  *
360  * Returns: The protocol for this URI.
361  */
362 gchar *
363 gst_uri_get_protocol (const gchar * uri)
364 {
365   gchar *colon;
366
367   g_return_val_if_fail (uri != NULL, NULL);
368   g_return_val_if_fail (gst_uri_is_valid (uri), NULL);
369
370   colon = strstr (uri, "://");
371
372   return g_strdown (g_strndup (uri, colon - uri));
373 }
374
375 /**
376  * gst_uri_has_protocol:
377  * @uri: an URI string
378  * @protocol: a protocol string (e.g. "http")
379  *
380  * Checks if the protocol of a given valid URI matches @protocol.
381  *
382  * Returns: %TRUE if the protocol matches.
383  *
384  * Since: 0.10.4
385  */
386 gboolean
387 gst_uri_has_protocol (const gchar * uri, const gchar * protocol)
388 {
389   gchar *colon;
390
391   g_return_val_if_fail (uri != NULL, FALSE);
392   g_return_val_if_fail (protocol != NULL, FALSE);
393   g_return_val_if_fail (gst_uri_is_valid (uri), FALSE);
394
395   colon = strstr (uri, "://");
396
397   if (colon == NULL)
398     return FALSE;
399
400   return (strncmp (uri, protocol, (size_t) (colon - uri)) == 0);
401 }
402
403 /**
404  * gst_uri_get_location:
405  * @uri: A URI string
406  *
407  * Extracts the location out of a given valid URI, ie. the protocol and "://"
408  * are stripped from the URI, which means that the location returned includes
409  * the hostname if one is specified. The returned string must be freed using
410  * g_free().
411  *
412  * Returns: The location for this URI. Returns NULL if the URI isn't valid. If
413  * the URI does not contain a location, an empty string is returned.
414  */
415 gchar *
416 gst_uri_get_location (const gchar * uri)
417 {
418   const gchar *colon;
419   gchar *unescaped = NULL;
420
421   g_return_val_if_fail (uri != NULL, NULL);
422   g_return_val_if_fail (gst_uri_is_valid (uri), NULL);
423
424   colon = strstr (uri, "://");
425
426   unescaped = unescape_string (colon + 3, "/");
427
428   /* On Windows an URI might look like file:///c:/foo/bar.txt or
429    * file:///c|/foo/bar.txt (some Netscape versions) and we want to
430    * return c:/foo/bar.txt as location rather than /c:/foo/bar.txt.
431    * Can't use g_filename_from_uri() here because it will only handle the
432    * file:// protocol */
433 #ifdef G_OS_WIN32
434   if (unescaped != NULL && unescaped[0] == '/' &&
435       g_ascii_isalpha (unescaped[1]) &&
436       (unescaped[2] == ':' || unescaped[2] == '|')) {
437     unescaped[2] = ':';
438     g_memmove (unescaped, unescaped + 1, strlen (unescaped + 1) + 1);
439   }
440 #endif
441
442   GST_LOG ("extracted location '%s' from URI '%s'", GST_STR_NULL (unescaped),
443       uri);;
444   return unescaped;
445 }
446
447 /**
448  * gst_uri_construct:
449  * @protocol: Protocol for URI
450  * @location: Location for URI
451  *
452  * Constructs a URI for a given valid protocol and location.
453  *
454  * Returns: a new string for this URI. Returns NULL if the given URI protocol
455  * is not valid, or the given location is NULL.
456  */
457 gchar *
458 gst_uri_construct (const gchar * protocol, const gchar * location)
459 {
460   char *escaped;
461   char *retval;
462
463   g_return_val_if_fail (gst_uri_protocol_is_valid (protocol), NULL);
464   g_return_val_if_fail (location != NULL, NULL);
465
466   escaped = escape_string (location);
467   retval = g_strdup_printf ("%s://%s", protocol, escaped);
468   g_free (escaped);
469
470   return retval;
471 }
472
473 typedef struct
474 {
475   GstURIType type;
476   const gchar *protocol;
477 }
478 SearchEntry;
479
480 static gboolean
481 search_by_entry (GstPluginFeature * feature, gpointer search_entry)
482 {
483   gchar **protocols;
484   GstElementFactory *factory;
485   SearchEntry *entry = (SearchEntry *) search_entry;
486
487   if (!GST_IS_ELEMENT_FACTORY (feature))
488     return FALSE;
489   factory = GST_ELEMENT_FACTORY (feature);
490
491   if (gst_element_factory_get_uri_type (factory) != entry->type)
492     return FALSE;
493
494   protocols = gst_element_factory_get_uri_protocols (factory);
495
496   if (protocols == NULL) {
497     g_warning ("Factory '%s' implements GstUriHandler interface but returned "
498         "no supported protocols!", gst_plugin_feature_get_name (feature));
499     return FALSE;
500   }
501
502   while (*protocols != NULL) {
503     if (g_ascii_strcasecmp (*protocols, entry->protocol) == 0)
504       return TRUE;
505     protocols++;
506   }
507   return FALSE;
508 }
509
510 static gint
511 sort_by_rank (gconstpointer a, gconstpointer b)
512 {
513   GstPluginFeature *first = GST_PLUGIN_FEATURE (a);
514   GstPluginFeature *second = GST_PLUGIN_FEATURE (b);
515
516   return gst_plugin_feature_get_rank (second) -
517       gst_plugin_feature_get_rank (first);
518 }
519
520 static GList *
521 get_element_factories_from_uri_protocol (const GstURIType type,
522     const gchar * protocol)
523 {
524   GList *possibilities;
525   SearchEntry entry;
526
527   g_return_val_if_fail (protocol, NULL);
528
529   entry.type = type;
530   entry.protocol = protocol;
531   possibilities = gst_registry_feature_filter (gst_registry_get_default (),
532       search_by_entry, FALSE, &entry);
533
534   return possibilities;
535 }
536
537 /**
538  * gst_uri_protocol_is_supported:
539  * @type: Whether to check for a source or a sink
540  * @protocol: Protocol that should be checked for (e.g. "http" or "smb")
541  *
542  * Checks if an element exists that supports the given URI protocol. Note
543  * that a positive return value does not imply that a subsequent call to
544  * gst_element_make_from_uri() is guaranteed to work.
545  *
546  * Returns: TRUE
547  *
548  * Since: 0.10.13
549 */
550 gboolean
551 gst_uri_protocol_is_supported (const GstURIType type, const gchar * protocol)
552 {
553   GList *possibilities;
554
555   g_return_val_if_fail (protocol, FALSE);
556
557   possibilities = get_element_factories_from_uri_protocol (type, protocol);
558
559   if (possibilities) {
560     g_list_free (possibilities);
561     return TRUE;
562   } else
563     return FALSE;
564 }
565
566 /**
567  * gst_element_make_from_uri:
568  * @type: Whether to create a source or a sink
569  * @uri: URI to create an element for
570  * @elementname: Name of created element, can be NULL.
571  *
572  * Creates an element for handling the given URI.
573  *
574  * Returns: a new element or NULL if none could be created
575  */
576 GstElement *
577 gst_element_make_from_uri (const GstURIType type, const gchar * uri,
578     const gchar * elementname)
579 {
580   GList *possibilities, *walk;
581   gchar *protocol;
582   GstElement *ret = NULL;
583
584   g_return_val_if_fail (GST_URI_TYPE_IS_VALID (type), NULL);
585   g_return_val_if_fail (gst_uri_is_valid (uri), NULL);
586
587   protocol = gst_uri_get_protocol (uri);
588   possibilities = get_element_factories_from_uri_protocol (type, protocol);
589   g_free (protocol);
590
591   if (!possibilities) {
592     GST_DEBUG ("No %s for URI '%s'", type == GST_URI_SINK ? "sink" : "source",
593         uri);
594     return NULL;
595   }
596
597   possibilities = g_list_sort (possibilities, sort_by_rank);
598   walk = possibilities;
599   while (walk) {
600     if ((ret = gst_element_factory_create (GST_ELEMENT_FACTORY (walk->data),
601                 elementname)) != NULL) {
602       GstURIHandler *handler = GST_URI_HANDLER (ret);
603
604       if (gst_uri_handler_set_uri (handler, uri))
605         break;
606       gst_object_unref (ret);
607       ret = NULL;
608     }
609     walk = walk->next;
610   }
611   gst_plugin_feature_list_free (possibilities);
612
613   GST_LOG_OBJECT (ret, "created %s for URL '%s'",
614       type == GST_URI_SINK ? "sink" : "source", uri);
615   return ret;
616 }
617
618 /**
619  * gst_uri_handler_get_uri_type:
620  * @handler: A #GstURIHandler.
621  *
622  * Gets the type of the given URI handler
623  *
624  * Returns: the #GstURIType of the URI handler.
625  * Returns #GST_URI_UNKNOWN if the @handler isn't implemented correctly.
626  */
627 guint
628 gst_uri_handler_get_uri_type (GstURIHandler * handler)
629 {
630   GstURIHandlerInterface *iface;
631   guint ret;
632
633   g_return_val_if_fail (GST_IS_URI_HANDLER (handler), GST_URI_UNKNOWN);
634
635   iface = GST_URI_HANDLER_GET_INTERFACE (handler);
636   g_return_val_if_fail (iface != NULL, GST_URI_UNKNOWN);
637   g_return_val_if_fail (iface->get_type != NULL, GST_URI_UNKNOWN);
638   ret = iface->get_type ();
639   g_return_val_if_fail (GST_URI_TYPE_IS_VALID (ret), GST_URI_UNKNOWN);
640
641   return ret;
642 }
643
644 /**
645  * gst_uri_handler_get_protocols:
646  * @handler: A #GstURIHandler.
647  *
648  * Gets the list of protocols supported by @handler. This list may not be
649  * modified.
650  *
651  * Returns: the supported protocols.
652  * Returns NULL if the @handler isn't implemented properly, or the @handler
653  * doesn't support any protocols.
654  */
655 gchar **
656 gst_uri_handler_get_protocols (GstURIHandler * handler)
657 {
658   GstURIHandlerInterface *iface;
659   gchar **ret;
660
661   g_return_val_if_fail (GST_IS_URI_HANDLER (handler), NULL);
662
663   iface = GST_URI_HANDLER_GET_INTERFACE (handler);
664   g_return_val_if_fail (iface != NULL, NULL);
665   g_return_val_if_fail (iface->get_protocols != NULL, NULL);
666   ret = iface->get_protocols ();
667   g_return_val_if_fail (ret != NULL, NULL);
668
669   return ret;
670 }
671
672 /**
673  * gst_uri_handler_get_uri:
674  * @handler: A #GstURIHandler
675  *
676  * Gets the currently handled URI.
677  *
678  * Returns: the URI currently handled by the @handler.
679  * Returns NULL if there are no URI currently handled. The returned
680  * string must not be modified or freed.
681  */
682 G_CONST_RETURN gchar *
683 gst_uri_handler_get_uri (GstURIHandler * handler)
684 {
685   GstURIHandlerInterface *iface;
686   const gchar *ret;
687
688   g_return_val_if_fail (GST_IS_URI_HANDLER (handler), NULL);
689
690   iface = GST_URI_HANDLER_GET_INTERFACE (handler);
691   g_return_val_if_fail (iface != NULL, NULL);
692   g_return_val_if_fail (iface->get_uri != NULL, NULL);
693   ret = iface->get_uri (handler);
694   if (ret != NULL)
695     g_return_val_if_fail (gst_uri_is_valid (ret), NULL);
696
697   return ret;
698 }
699
700 /**
701  * gst_uri_handler_set_uri:
702  * @handler: A #GstURIHandler
703  * @uri: URI to set
704  *
705  * Tries to set the URI of the given handler.
706  *
707  * Returns: TRUE if the URI was set successfully, else FALSE.
708  */
709 gboolean
710 gst_uri_handler_set_uri (GstURIHandler * handler, const gchar * uri)
711 {
712   GstURIHandlerInterface *iface;
713
714   g_return_val_if_fail (GST_IS_URI_HANDLER (handler), FALSE);
715   g_return_val_if_fail (gst_uri_is_valid (uri), FALSE);
716
717   iface = GST_URI_HANDLER_GET_INTERFACE (handler);
718   g_return_val_if_fail (iface != NULL, FALSE);
719   g_return_val_if_fail (iface->set_uri != NULL, FALSE);
720   return iface->set_uri (handler, uri);
721 }
722
723 /**
724  * gst_uri_handler_new_uri:
725  * @handler: A #GstURIHandler
726  * @uri: new URI or NULL if it was unset
727  *
728  * Emits the new-uri signal for a given handler, when that handler has a new URI.
729  * This function should only be called by URI handlers themselves.
730  */
731 void
732 gst_uri_handler_new_uri (GstURIHandler * handler, const gchar * uri)
733 {
734   g_return_if_fail (GST_IS_URI_HANDLER (handler));
735
736   g_signal_emit_by_name (handler, "new-uri", uri);
737 }