2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
4 * 2014 David Waring, British Broadcasting Corporation
5 * <david.waring@rd.bbc.co.uk>
7 * gsturi.h: Header for uri to element mappings and URI manipulation.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
30 #include <glib-object.h>
31 #include <gst/gstelement.h>
32 #include <gst/gstconfig.h>
34 #include "gstminiobject.h"
38 GQuark gst_uri_error_quark (void);
43 * Get access to the error quark of the uri subsystem.
45 #define GST_URI_ERROR gst_uri_error_quark ()
49 * @GST_URI_ERROR_UNSUPPORTED_PROTOCOL: The protocol is not supported
50 * @GST_URI_ERROR_BAD_URI: There was a problem with the URI
51 * @GST_URI_ERROR_BAD_STATE: Could not set or change the URI because the
52 * URI handler was in a state where that is not possible or not permitted
53 * @GST_URI_ERROR_BAD_REFERENCE: There was a problem with the entity that
56 * Different URI-related errors that can occur.
60 GST_URI_ERROR_UNSUPPORTED_PROTOCOL,
61 GST_URI_ERROR_BAD_URI,
62 GST_URI_ERROR_BAD_STATE,
63 GST_URI_ERROR_BAD_REFERENCE
68 * @GST_URI_UNKNOWN: The URI direction is unknown
69 * @GST_URI_SINK: The URI is a consumer.
70 * @GST_URI_SRC: The URI is a producer.
72 * The different types of URI direction.
82 * GST_URI_TYPE_IS_VALID:
83 * @type: A #GstURIType
85 * Tests if the type direction is valid.
87 #define GST_URI_TYPE_IS_VALID(type) ((type) == GST_URI_SRC || (type) == GST_URI_SINK)
89 /* uri handler functions */
90 #define GST_TYPE_URI_HANDLER (gst_uri_handler_get_type ())
91 #define GST_URI_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_URI_HANDLER, GstURIHandler))
92 #define GST_IS_URI_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_URI_HANDLER))
93 #define GST_URI_HANDLER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GST_TYPE_URI_HANDLER, GstURIHandlerInterface))
98 * Opaque #GstURIHandler structure.
100 typedef struct _GstURIHandler GstURIHandler;
101 typedef struct _GstURIHandlerInterface GstURIHandlerInterface;
104 * GstURIHandlerInterface:
105 * @parent: The parent interface type
106 * @get_type: Method to tell whether the element handles source or sink URI.
107 * @get_protocols: Method to return the list of protocols handled by the element.
108 * @get_uri: Method to return the URI currently handled by the element.
109 * @set_uri: Method to set a new URI.
111 * Any #GstElement using this interface should implement these methods.
113 struct _GstURIHandlerInterface {
114 GTypeInterface parent;
118 /* querying capabilities */
119 GstURIType (* get_type) (GType type);
120 const gchar * const * (* get_protocols) (GType type);
122 /* using the interface */
123 gchar * (* get_uri) (GstURIHandler * handler);
124 gboolean (* set_uri) (GstURIHandler * handler,
129 /* general URI functions */
131 gboolean gst_uri_protocol_is_valid (const gchar * protocol);
132 gboolean gst_uri_protocol_is_supported (const GstURIType type,
133 const gchar *protocol);
134 gboolean gst_uri_is_valid (const gchar * uri);
135 gchar * gst_uri_get_protocol (const gchar * uri) G_GNUC_MALLOC;
136 gboolean gst_uri_has_protocol (const gchar * uri,
137 const gchar * protocol);
138 gchar * gst_uri_get_location (const gchar * uri) G_GNUC_MALLOC;
139 gchar * gst_uri_construct (const gchar * protocol,
140 const gchar * location) G_GNUC_MALLOC;
142 gchar * gst_filename_to_uri (const gchar * filename,
143 GError ** error) G_GNUC_MALLOC;
145 GstElement * gst_element_make_from_uri (const GstURIType type,
147 const gchar * elementname,
148 GError ** error) G_GNUC_MALLOC;
150 /* accessing the interface */
151 GType gst_uri_handler_get_type (void);
153 GstURIType gst_uri_handler_get_uri_type (GstURIHandler * handler);
154 const gchar * const * gst_uri_handler_get_protocols (GstURIHandler * handler);
155 gchar * gst_uri_handler_get_uri (GstURIHandler * handler) G_GNUC_MALLOC;
156 gboolean gst_uri_handler_set_uri (GstURIHandler * handler,
161 * GstUri Type macros.
163 #define GST_TYPE_URI (gst_uri_get_type ())
164 #define GST_IS_URI(obj) (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_URI))
165 #define GST_URI_CAST(obj) ((GstUri *)(obj))
166 #define GST_URI_CONST_CAST(obj) ((const GstUri *)(obj))
167 #define GST_URI(obj) (GST_URI_CAST(obj))
172 * This is a private structure that holds the various parts of a parsed URI.
175 typedef struct _GstUri GstUri;
180 * Value for #GstUri.port to indicate no port number.
182 #define GST_URI_NO_PORT 0
184 /* used by GST_TYPE_URI */
185 GType gst_uri_get_type (void);
188 * Method definitions.
191 GstUri * gst_uri_new (const gchar * scheme,
192 const gchar * userinfo,
197 const gchar * fragment) G_GNUC_MALLOC;
198 GstUri * gst_uri_new_with_base (GstUri * base,
199 const gchar * scheme,
200 const gchar * userinfo,
205 const gchar * fragment) G_GNUC_MALLOC;
206 GstUri * gst_uri_from_string (const gchar * uri) G_GNUC_MALLOC;
207 GstUri * gst_uri_from_string_with_base (GstUri * base,
208 const gchar * uri) G_GNUC_MALLOC;
209 gboolean gst_uri_equal (const GstUri * first,
210 const GstUri * second);
211 GstUri * gst_uri_join (GstUri * base_uri,
213 gchar * gst_uri_join_strings (const gchar * base_uri,
214 const gchar * ref_uri) G_GNUC_MALLOC;
215 gboolean gst_uri_is_writable (const GstUri * uri);
216 GstUri * gst_uri_make_writable (GstUri * uri);
217 gchar * gst_uri_to_string (const GstUri * uri) G_GNUC_MALLOC;
218 gboolean gst_uri_is_normalized (const GstUri * uri);
219 gboolean gst_uri_normalize (GstUri * uri);
220 const gchar * gst_uri_get_scheme (const GstUri * uri);
221 gboolean gst_uri_set_scheme (GstUri * uri, const gchar * scheme);
222 const gchar * gst_uri_get_userinfo (const GstUri * uri);
223 gboolean gst_uri_set_userinfo (GstUri * uri, const gchar * userinfo);
224 const gchar * gst_uri_get_host (const GstUri * uri);
225 gboolean gst_uri_set_host (GstUri * uri, const gchar * host);
226 guint gst_uri_get_port (const GstUri * uri);
227 gboolean gst_uri_set_port (GstUri * uri, guint port);
228 gchar * gst_uri_get_path (const GstUri * uri);
229 gboolean gst_uri_set_path (GstUri * uri, const gchar * path);
230 gchar * gst_uri_get_path_string (const GstUri * uri);
231 gboolean gst_uri_set_path_string (GstUri * uri, const gchar * path);
232 GList * gst_uri_get_path_segments (const GstUri * uri);
233 gboolean gst_uri_set_path_segments (GstUri * uri, GList * path_segments);
234 gboolean gst_uri_append_path (GstUri * uri,
235 const gchar * relative_path);
236 gboolean gst_uri_append_path_segment (GstUri * uri,
237 const gchar * path_segment);
238 gchar * gst_uri_get_query_string (const GstUri * uri);
239 gboolean gst_uri_set_query_string (GstUri * uri, const gchar * query);
240 GHashTable * gst_uri_get_query_table (const GstUri * uri);
241 gboolean gst_uri_set_query_table (GstUri * uri,
242 GHashTable * query_table);
243 gboolean gst_uri_set_query_value (GstUri * uri, const gchar * query_key,
244 const gchar * query_value);
245 gboolean gst_uri_remove_query_key (GstUri * uri, const gchar * query_key);
246 gboolean gst_uri_query_has_key (const GstUri * uri,
247 const gchar * query_key);
248 const gchar * gst_uri_get_query_value (const GstUri * uri,
249 const gchar * query_key);
250 GList * gst_uri_get_query_keys (const GstUri * uri);
251 const gchar * gst_uri_get_fragment (const GstUri * uri);
252 gboolean gst_uri_set_fragment (GstUri * uri, const gchar * fragment);
256 * @uri: This #GstUri object.
258 * Create a new #GstUri object with the same data as this #GstUri object.
259 * If @uri is %NULL then returns %NULL.
261 * Returns: (transfer full): A new #GstUri object which is a copy of this
264 #ifdef _FOOL_GTK_DOC_
265 G_INLINE_FUNC GstUri * gst_uri_copy (const GstUri * uri);
268 static inline GstUri *
269 gst_uri_copy (const GstUri * uri)
271 return GST_URI_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (uri)));
276 * @uri: (transfer none): This #GstUri object.
278 * Add a reference to this #GstUri object. See gst_mini_object_ref() for further
281 * Returns: This object with the reference count incremented.
283 #ifdef _FOOL_GTK_DOC_
284 G_INLINE_FUNC GstUri * gst_uri_ref (GstUri * uri);
287 static inline GstUri *
288 gst_uri_ref (GstUri * uri)
290 return GST_URI_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (uri)));
295 * @uri: (transfer full): This #GstUri object.
297 * Decrement the reference count to this #GstUri object.
299 * If the reference count drops to 0 then finalize this object.
301 * See gst_mini_object_unref() for further info.
303 #ifdef _FOOL_GTK_DOC_
304 G_INLINE_FUNC void gst_uri_unref (GstUri * uri);
308 gst_uri_unref (GstUri * uri)
310 gst_mini_object_unref (GST_MINI_OBJECT_CAST (uri));
315 #endif /* __GST_URI_H__ */