Move dataurisrc element from -bad
[platform/upstream/gstreamer.git] / gst / gsturi.h
1 /* GStreamer
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>
6  *
7  * gsturi.h: Header for uri to element mappings and URI manipulation.
8  *
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.
13  *
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.
18  *
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.
23  */
24
25
26 #ifndef __GST_URI_H__
27 #define __GST_URI_H__
28
29 #include <glib.h>
30 #include <glib-object.h>
31 #include <gst/gstelement.h>
32 #include <gst/gstconfig.h>
33
34 #include "gstminiobject.h"
35
36 G_BEGIN_DECLS
37
38 GQuark gst_uri_error_quark (void);
39
40 /**
41  * GST_URI_ERROR:
42  *
43  * Get access to the error quark of the uri subsystem.
44  */
45 #define GST_URI_ERROR gst_uri_error_quark ()
46
47 /**
48  * GstURIError:
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
54  *     the URI references
55  *
56  * Different URI-related errors that can occur.
57  */
58 typedef enum
59 {
60   GST_URI_ERROR_UNSUPPORTED_PROTOCOL,
61   GST_URI_ERROR_BAD_URI,
62   GST_URI_ERROR_BAD_STATE,
63   GST_URI_ERROR_BAD_REFERENCE
64 } GstURIError;
65
66 /**
67  * GstURIType:
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.
71  *
72  * The different types of URI direction.
73  */
74
75 typedef enum {
76   GST_URI_UNKNOWN,
77   GST_URI_SINK,
78   GST_URI_SRC
79 } GstURIType;
80
81 /**
82  * GST_URI_TYPE_IS_VALID:
83  * @type: A #GstURIType
84  *
85  * Tests if the type direction is valid.
86  */
87 #define GST_URI_TYPE_IS_VALID(type) ((type) == GST_URI_SRC || (type) == GST_URI_SINK)
88
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))
94
95 /**
96  * GstURIHandler:
97  *
98  * Opaque #GstURIHandler structure.
99  */
100 typedef struct _GstURIHandler GstURIHandler;
101 typedef struct _GstURIHandlerInterface GstURIHandlerInterface;
102
103 /**
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.
110  *
111  * Any #GstElement using this interface should implement these methods.
112  */
113 struct _GstURIHandlerInterface {
114   GTypeInterface parent;
115
116   /* vtable */
117   /*< public >*/
118   /* querying capabilities */
119   GstURIType             (* get_type)           (GType type);
120   const gchar * const *  (* get_protocols)      (GType type);
121
122   /* using the interface */
123   gchar *                (* get_uri)            (GstURIHandler * handler);
124   gboolean               (* set_uri)            (GstURIHandler * handler,
125                                                  const gchar   * uri,
126                                                  GError       ** error);
127 };
128
129 /* general URI functions */
130
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;
141
142 gchar *         gst_filename_to_uri             (const gchar * filename,
143                                                  GError     ** error) G_GNUC_MALLOC;
144
145 GstElement *    gst_element_make_from_uri       (const GstURIType type,
146                                                  const gchar *    uri,
147                                                  const gchar *    elementname,
148                                                  GError      **   error) G_GNUC_MALLOC;
149
150 /* accessing the interface */
151 GType                 gst_uri_handler_get_type (void);
152
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,
157                                                      const gchar   * uri,
158                                                      GError       ** error);
159
160 /*
161  * GstUri Type macros.
162  */
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))
168
169 /**
170  * GstUri:
171  *
172  * This is a private structure that holds the various parts of a parsed URI.
173  */
174 struct _GstUri;
175 typedef struct _GstUri GstUri;
176
177 /**
178  * GST_URI_NO_PORT:
179  *
180  * Value for #GstUri<!-- -->.port to indicate no port number.
181  */
182 #define GST_URI_NO_PORT 0
183
184 /* used by GST_TYPE_URI */
185 GType gst_uri_get_type (void);
186
187 /*
188  * Method definitions.
189  */
190
191 GstUri * gst_uri_new                   (const gchar * scheme,
192                                         const gchar * userinfo,
193                                         const gchar * host,
194                                         guint port,
195                                         const gchar * path,
196                                         const gchar * query,
197                                         const gchar * fragment) G_GNUC_MALLOC;
198 GstUri * gst_uri_new_with_base         (GstUri * base,
199                                         const gchar * scheme,
200                                         const gchar * userinfo,
201                                         const gchar * host,
202                                         guint port,
203                                         const gchar * path,
204                                         const gchar * query,
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,
212                                         GstUri * ref_uri) G_GNUC_WARN_UNUSED_RESULT;
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) G_GNUC_WARN_UNUSED_RESULT;
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);
253
254 /**
255  * gst_uri_copy:
256  * @uri: This #GstUri object.
257  *
258  * Create a new #GstUri object with the same data as this #GstUri object.
259  * If @uri is %NULL then returns %NULL.
260  *
261  * Returns: (transfer full): A new #GstUri object which is a copy of this
262  *          #GstUri or %NULL.
263  */
264 static inline GstUri *
265 gst_uri_copy (const GstUri * uri)
266 {
267   return GST_URI_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (uri)));
268 }
269
270 /**
271  * gst_uri_ref:
272  * @uri: (transfer none): This #GstUri object.
273  *
274  * Add a reference to this #GstUri object. See gst_mini_object_ref() for further
275  * info.
276  *
277  * Returns: This object with the reference count incremented.
278  */
279 static inline GstUri *
280 gst_uri_ref (GstUri * uri)
281 {
282   return GST_URI_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (uri)));
283 }
284
285 /**
286  * gst_uri_unref:
287  * @uri: (transfer full): This #GstUri object.
288  *
289  * Decrement the reference count to this #GstUri object.
290  *
291  * If the reference count drops to 0 then finalize this object.
292  *
293  * See gst_mini_object_unref() for further info.
294  */
295 static inline void
296 gst_uri_unref (GstUri * uri)
297 {
298   gst_mini_object_unref (GST_MINI_OBJECT_CAST (uri));
299 }
300
301 #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
302 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstUri, gst_uri_unref)
303 #endif
304
305 G_END_DECLS
306
307 #endif /* __GST_URI_H__ */