gsturi.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. #ifndef __GST_URI_H__
  25. #define __GST_URI_H__
  26. #include <glib.h>
  27. #include <glib-object.h>
  28. #include <gst/gstelement.h>
  29. #include <gst/gstconfig.h>
  30. #include "gstminiobject.h"
  31. G_BEGIN_DECLS
  32. GQuark gst_uri_error_quark (void);
  33. /**
  34. * GST_URI_ERROR:
  35. *
  36. * Get access to the error quark of the uri subsystem.
  37. */
  38. #define GST_URI_ERROR gst_uri_error_quark ()
  39. /**
  40. * GstURIError:
  41. * @GST_URI_ERROR_UNSUPPORTED_PROTOCOL: The protocol is not supported
  42. * @GST_URI_ERROR_BAD_URI: There was a problem with the URI
  43. * @GST_URI_ERROR_BAD_STATE: Could not set or change the URI because the
  44. * URI handler was in a state where that is not possible or not permitted
  45. * @GST_URI_ERROR_BAD_REFERENCE: There was a problem with the entity that
  46. * the URI references
  47. *
  48. * Different URI-related errors that can occur.
  49. */
  50. typedef enum
  51. {
  52. GST_URI_ERROR_UNSUPPORTED_PROTOCOL,
  53. GST_URI_ERROR_BAD_URI,
  54. GST_URI_ERROR_BAD_STATE,
  55. GST_URI_ERROR_BAD_REFERENCE
  56. } GstURIError;
  57. /**
  58. * GstURIType:
  59. * @GST_URI_UNKNOWN: The URI direction is unknown
  60. * @GST_URI_SINK: The URI is a consumer.
  61. * @GST_URI_SRC: The URI is a producer.
  62. *
  63. * The different types of URI direction.
  64. */
  65. typedef enum {
  66. GST_URI_UNKNOWN,
  67. GST_URI_SINK,
  68. GST_URI_SRC
  69. } GstURIType;
  70. /**
  71. * GST_URI_TYPE_IS_VALID:
  72. * @type: A #GstURIType
  73. *
  74. * Tests if the type direction is valid.
  75. */
  76. #define GST_URI_TYPE_IS_VALID(type) ((type) == GST_URI_SRC || (type) == GST_URI_SINK)
  77. /* uri handler functions */
  78. #define GST_TYPE_URI_HANDLER (gst_uri_handler_get_type ())
  79. #define GST_URI_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_URI_HANDLER, GstURIHandler))
  80. #define GST_IS_URI_HANDLER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_URI_HANDLER))
  81. #define GST_URI_HANDLER_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GST_TYPE_URI_HANDLER, GstURIHandlerInterface))
  82. /**
  83. * GstURIHandler:
  84. *
  85. * Opaque #GstURIHandler structure.
  86. */
  87. typedef struct _GstURIHandler GstURIHandler;
  88. typedef struct _GstURIHandlerInterface GstURIHandlerInterface;
  89. /**
  90. * GstURIHandlerInterface:
  91. * @parent: The parent interface type
  92. * @get_type: Method to tell whether the element handles source or sink URI.
  93. * @get_protocols: Method to return the list of protocols handled by the element.
  94. * @get_uri: Method to return the URI currently handled by the element.
  95. * @set_uri: Method to set a new URI.
  96. *
  97. * Any #GstElement using this interface should implement these methods.
  98. */
  99. struct _GstURIHandlerInterface {
  100. GTypeInterface parent;
  101. /* vtable */
  102. /*< public >*/
  103. /* querying capabilities */
  104. GstURIType (* get_type) (GType type);
  105. const gchar * const * (* get_protocols) (GType type);
  106. /* using the interface */
  107. gchar * (* get_uri) (GstURIHandler * handler);
  108. gboolean (* set_uri) (GstURIHandler * handler,
  109. const gchar * uri,
  110. GError ** error);
  111. };
  112. /* general URI functions */
  113. gboolean gst_uri_protocol_is_valid (const gchar * protocol);
  114. gboolean gst_uri_protocol_is_supported (const GstURIType type,
  115. const gchar *protocol);
  116. gboolean gst_uri_is_valid (const gchar * uri);
  117. gchar * gst_uri_get_protocol (const gchar * uri) G_GNUC_MALLOC;
  118. gboolean gst_uri_has_protocol (const gchar * uri,
  119. const gchar * protocol);
  120. gchar * gst_uri_get_location (const gchar * uri) G_GNUC_MALLOC;
  121. gchar * gst_uri_construct (const gchar * protocol,
  122. const gchar * location) G_GNUC_MALLOC;
  123. gchar * gst_filename_to_uri (const gchar * filename,
  124. GError ** error) G_GNUC_MALLOC;
  125. GstElement * gst_element_make_from_uri (const GstURIType type,
  126. const gchar * uri,
  127. const gchar * elementname,
  128. GError ** error) G_GNUC_MALLOC;
  129. /* accessing the interface */
  130. GType gst_uri_handler_get_type (void);
  131. GstURIType gst_uri_handler_get_uri_type (GstURIHandler * handler);
  132. const gchar * const * gst_uri_handler_get_protocols (GstURIHandler * handler);
  133. gchar * gst_uri_handler_get_uri (GstURIHandler * handler) G_GNUC_MALLOC;
  134. gboolean gst_uri_handler_set_uri (GstURIHandler * handler,
  135. const gchar * uri,
  136. GError ** error);
  137. /*
  138. * GstUri Type macros.
  139. */
  140. #define GST_TYPE_URI (gst_uri_get_type ())
  141. #define GST_IS_URI(obj) (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_URI))
  142. #define GST_URI_CAST(obj) ((GstUri *)(obj))
  143. #define GST_URI_CONST_CAST(obj) ((const GstUri *)(obj))
  144. #define GST_URI(obj) (GST_URI_CAST(obj))
  145. /**
  146. * GstUri:
  147. *
  148. * This is a private structure that holds the various parts of a parsed URI.
  149. */
  150. struct _GstUri;
  151. typedef struct _GstUri GstUri;
  152. /**
  153. * GST_URI_NO_PORT:
  154. *
  155. * Value for #GstUri<!-- -->.port to indicate no port number.
  156. */
  157. #define GST_URI_NO_PORT 0
  158. /* used by GST_TYPE_URI */
  159. GType gst_uri_get_type (void);
  160. /*
  161. * Method definitions.
  162. */
  163. GstUri * gst_uri_new (const gchar * scheme,
  164. const gchar * userinfo,
  165. const gchar * host,
  166. guint port,
  167. const gchar * path,
  168. const gchar * query,
  169. const gchar * fragment) G_GNUC_MALLOC;
  170. GstUri * gst_uri_new_with_base (GstUri * base,
  171. const gchar * scheme,
  172. const gchar * userinfo,
  173. const gchar * host,
  174. guint port,
  175. const gchar * path,
  176. const gchar * query,
  177. const gchar * fragment) G_GNUC_MALLOC;
  178. GstUri * gst_uri_from_string (const gchar * uri) G_GNUC_MALLOC;
  179. GstUri * gst_uri_from_string_with_base (GstUri * base,
  180. const gchar * uri) G_GNUC_MALLOC;
  181. gboolean gst_uri_equal (const GstUri * first,
  182. const GstUri * second);
  183. GstUri * gst_uri_join (GstUri * base_uri,
  184. GstUri * ref_uri);
  185. gchar * gst_uri_join_strings (const gchar * base_uri,
  186. const gchar * ref_uri) G_GNUC_MALLOC;
  187. gboolean gst_uri_is_writable (const GstUri * uri);
  188. GstUri * gst_uri_make_writable (GstUri * uri);
  189. gchar * gst_uri_to_string (const GstUri * uri) G_GNUC_MALLOC;
  190. gboolean gst_uri_is_normalized (const GstUri * uri);
  191. gboolean gst_uri_normalize (GstUri * uri);
  192. const gchar * gst_uri_get_scheme (const GstUri * uri);
  193. gboolean gst_uri_set_scheme (GstUri * uri, const gchar * scheme);
  194. const gchar * gst_uri_get_userinfo (const GstUri * uri);
  195. gboolean gst_uri_set_userinfo (GstUri * uri, const gchar * userinfo);
  196. const gchar * gst_uri_get_host (const GstUri * uri);
  197. gboolean gst_uri_set_host (GstUri * uri, const gchar * host);
  198. guint gst_uri_get_port (const GstUri * uri);
  199. gboolean gst_uri_set_port (GstUri * uri, guint port);
  200. gchar * gst_uri_get_path (const GstUri * uri);
  201. gboolean gst_uri_set_path (GstUri * uri, const gchar * path);
  202. gchar * gst_uri_get_path_string (const GstUri * uri);
  203. gboolean gst_uri_set_path_string (GstUri * uri, const gchar * path);
  204. GList * gst_uri_get_path_segments (const GstUri * uri);
  205. gboolean gst_uri_set_path_segments (GstUri * uri, GList * path_segments);
  206. gboolean gst_uri_append_path (GstUri * uri,
  207. const gchar * relative_path);
  208. gboolean gst_uri_append_path_segment (GstUri * uri,
  209. const gchar * path_segment);
  210. gchar * gst_uri_get_query_string (const GstUri * uri);
  211. gboolean gst_uri_set_query_string (GstUri * uri, const gchar * query);
  212. GHashTable * gst_uri_get_query_table (const GstUri * uri);
  213. gboolean gst_uri_set_query_table (GstUri * uri,
  214. GHashTable * query_table);
  215. gboolean gst_uri_set_query_value (GstUri * uri, const gchar * query_key,
  216. const gchar * query_value);
  217. gboolean gst_uri_remove_query_key (GstUri * uri, const gchar * query_key);
  218. gboolean gst_uri_query_has_key (const GstUri * uri,
  219. const gchar * query_key);
  220. const gchar * gst_uri_get_query_value (const GstUri * uri,
  221. const gchar * query_key);
  222. GList * gst_uri_get_query_keys (const GstUri * uri);
  223. const gchar * gst_uri_get_fragment (const GstUri * uri);
  224. gboolean gst_uri_set_fragment (GstUri * uri, const gchar * fragment);
  225. /**
  226. * gst_uri_copy:
  227. * @uri: This #GstUri object.
  228. *
  229. * Create a new #GstUri object with the same data as this #GstUri object.
  230. * If @uri is %NULL then returns %NULL.
  231. *
  232. * Returns: (transfer full): A new #GstUri object which is a copy of this
  233. * #GstUri or %NULL.
  234. */
  235. static inline GstUri *
  236. gst_uri_copy (const GstUri * uri)
  237. {
  238. return GST_URI_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (uri)));
  239. }
  240. /**
  241. * gst_uri_ref:
  242. * @uri: (transfer none): This #GstUri object.
  243. *
  244. * Add a reference to this #GstUri object. See gst_mini_object_ref() for further
  245. * info.
  246. *
  247. * Returns: This object with the reference count incremented.
  248. */
  249. static inline GstUri *
  250. gst_uri_ref (GstUri * uri)
  251. {
  252. return GST_URI_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (uri)));
  253. }
  254. /**
  255. * gst_uri_unref:
  256. * @uri: (transfer full): This #GstUri object.
  257. *
  258. * Decrement the reference count to this #GstUri object.
  259. *
  260. * If the reference count drops to 0 then finalize this object.
  261. *
  262. * See gst_mini_object_unref() for further info.
  263. */
  264. static inline void
  265. gst_uri_unref (GstUri * uri)
  266. {
  267. gst_mini_object_unref (GST_MINI_OBJECT_CAST (uri));
  268. }
  269. #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
  270. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstUri, gst_uri_unref)
  271. #endif
  272. G_END_DECLS
  273. #endif /* __GST_URI_H__ */