GstUri: Add GstUri miniobject to handle URIs in an RFC 3986 compliant fashion

https://bugzilla.gnome.org/show_bug.cgi?id=725221
This commit is contained in:
David Waring 2014-07-31 22:18:53 +01:00 committed by Sebastian Dröge
parent 9494b69035
commit 54c5f1855c
6 changed files with 2671 additions and 2 deletions

View file

@ -108,6 +108,7 @@ Windows. It is released under the GNU Library General Public License
<xi:include href="xml/gsttocsetter.xml" />
<xi:include href="xml/gsttypefind.xml" />
<xi:include href="xml/gsttypefindfactory.xml" />
<xi:include href="xml/gsturi.xml" />
<xi:include href="xml/gsturihandler.xml" />
<xi:include href="xml/gstutils.xml" />
<xi:include href="xml/gstvalue.xml" />

View file

@ -3044,6 +3044,60 @@ gst_uri_handler_get_type
gst_uri_type_get_type
</SECTION>
<SECTION>
<FILE>gsturi</FILE>
<TITLE>GstUri</TITLE>
GST_URI_CAST
GST_URI_CONST_CAST
GstUri
gst_uri_new
gst_uri_new_with_base
gst_uri_from_string
gst_uri_from_string_with_base
gst_uri_copy
gst_uri_equal
gst_uri_join
gst_uri_join_strings
gst_uri_is_writable
gst_uri_make_writable
gst_uri_to_string
gst_uri_ref
gst_uri_unref
gst_uri_is_normalized
gst_uri_normalize
gst_uri_get_scheme
gst_uri_set_scheme
gst_uri_get_userinfo
gst_uri_set_userinfo
gst_uri_get_host
gst_uri_set_host
gst_uri_get_port
gst_uri_set_port
gst_uri_get_path
gst_uri_set_path
gst_uri_get_path_string
gst_uri_set_path_string
gst_uri_get_path_segments
gst_uri_set_path_segments
gst_uri_append_path
gst_uri_append_path_segment
gst_uri_get_query_string
gst_uri_set_query_string
gst_uri_get_query_table
gst_uri_set_query_table
gst_uri_get_query_value
gst_uri_set_query_value
gst_uri_remove_query_key
gst_uri_query_has_key
gst_uri_get_query_keys
gst_uri_get_fragment
gst_uri_set_fragment
<SUBSECTION Standard>
GST_IS_URI
GST_TYPE_URI
GST_URI
gst_uri_get_type
</SECTION>
<SECTION>
<FILE>gstutils</FILE>

File diff suppressed because it is too large Load diff

View file

@ -1,8 +1,10 @@
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wtay@chello.be>
* 2014 David Waring, British Broadcasting Corporation
* <david.waring@rd.bbc.co.uk>
*
* gsturi.h: Header for uri to element mappings
* gsturi.h: Header for uri to element mappings and URI manipulation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -25,7 +27,11 @@
#define __GST_URI_H__
#include <glib.h>
#include <glib-object.h>
#include <gst/gstelement.h>
#include <gst/gstconfig.h>
#include "gstminiobject.h"
G_BEGIN_DECLS
@ -151,6 +157,159 @@ gboolean gst_uri_handler_set_uri (GstURIHandler * handler,
const gchar * uri,
GError ** error);
/*
* GstUri Type macros.
*/
#define GST_TYPE_URI (gst_uri_get_type ())
#define GST_IS_URI(obj) (GST_IS_MINI_OBJECT_TYPE (obj, GST_TYPE_URI))
#define GST_URI_CAST(obj) ((GstUri *)(obj))
#define GST_URI_CONST_CAST(obj) ((const GstUri *)(obj))
#define GST_URI(obj) (GST_URI_CAST(obj))
/**
* GstUri:
*
* This is a private structure that holds the various parts of a parsed URI.
*/
struct _GstUri;
typedef struct _GstUri GstUri;
/**
* GST_URI_NO_PORT:
*
* Value for #GstUri.port to indicate no port number.
*/
#define GST_URI_NO_PORT 0
/* used by GST_TYPE_URI */
GType gst_uri_get_type (void);
/*
* Method definitions.
*/
GstUri * gst_uri_new (const gchar * scheme,
const gchar * userinfo,
const gchar * host,
guint port,
const gchar * path,
const gchar * query,
const gchar * fragment) G_GNUC_MALLOC;
GstUri * gst_uri_new_with_base (GstUri * base,
const gchar * scheme,
const gchar * userinfo,
const gchar * host,
guint port,
const gchar * path,
const gchar * query,
const gchar * fragment) G_GNUC_MALLOC;
GstUri * gst_uri_from_string (const gchar * uri) G_GNUC_MALLOC;
GstUri * gst_uri_from_string_with_base (GstUri * base,
const gchar * uri) G_GNUC_MALLOC;
gboolean gst_uri_equal (const GstUri * first,
const GstUri * second);
GstUri * gst_uri_join (GstUri * base_uri,
GstUri * ref_uri);
gchar * gst_uri_join_strings (const gchar * base_uri,
const gchar * ref_uri) G_GNUC_MALLOC;
gboolean gst_uri_is_writable (const GstUri * uri);
GstUri * gst_uri_make_writable (GstUri * uri);
gchar * gst_uri_to_string (const GstUri * uri) G_GNUC_MALLOC;
gboolean gst_uri_is_normalized (const GstUri * uri);
gboolean gst_uri_normalize (GstUri * uri);
const gchar * gst_uri_get_scheme (const GstUri * uri);
gboolean gst_uri_set_scheme (GstUri * uri, const gchar * scheme);
const gchar * gst_uri_get_userinfo (const GstUri * uri);
gboolean gst_uri_set_userinfo (GstUri * uri, const gchar * userinfo);
const gchar * gst_uri_get_host (const GstUri * uri);
gboolean gst_uri_set_host (GstUri * uri, const gchar * host);
guint gst_uri_get_port (const GstUri * uri);
gboolean gst_uri_set_port (GstUri * uri, guint port);
gchar * gst_uri_get_path (const GstUri * uri);
gboolean gst_uri_set_path (GstUri * uri, const gchar * path);
gchar * gst_uri_get_path_string (const GstUri * uri);
gboolean gst_uri_set_path_string (GstUri * uri, const gchar * path);
GList * gst_uri_get_path_segments (const GstUri * uri);
gboolean gst_uri_set_path_segments (GstUri * uri, GList * path_segments);
gboolean gst_uri_append_path (GstUri * uri,
const gchar * relative_path);
gboolean gst_uri_append_path_segment (GstUri * uri,
const gchar * path_segment);
gchar * gst_uri_get_query_string (const GstUri * uri);
gboolean gst_uri_set_query_string (GstUri * uri, const gchar * query);
GHashTable * gst_uri_get_query_table (const GstUri * uri);
gboolean gst_uri_set_query_table (GstUri * uri,
GHashTable * query_table);
gboolean gst_uri_set_query_value (GstUri * uri, const gchar * query_key,
const gchar * query_value);
gboolean gst_uri_remove_query_key (GstUri * uri, const gchar * query_key);
gboolean gst_uri_query_has_key (const GstUri * uri,
const gchar * query_key);
const gchar * gst_uri_get_query_value (const GstUri * uri,
const gchar * query_key);
GList * gst_uri_get_query_keys (const GstUri * uri);
const gchar * gst_uri_get_fragment (const GstUri * uri);
gboolean gst_uri_set_fragment (GstUri * uri, const gchar * fragment);
/**
* gst_uri_copy:
* @uri: This #GstUri object.
*
* Create a new #GstUri object with the same data as this #GstUri object.
* If @uri is %NULL then returns %NULL.
*
* Returns: (transfer full): A new #GstUri object which is a copy of this
* #GstUri or %NULL.
*/
#ifdef _FOOL_GTK_DOC_
G_INLINE_FUNC GstUri * gst_uri_copy (const GstUri * uri);
#endif
static inline GstUri *
gst_uri_copy (const GstUri * uri)
{
return GST_URI_CAST (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (uri)));
}
/**
* gst_uri_ref:
* @uri: (transfer none): This #GstUri object.
*
* Add a reference to this #GstUri object. See gst_mini_object_ref() for further
* info.
*
* Returns: This object with the reference count incremented.
*/
#ifdef _FOOL_GTK_DOC_
G_INLINE_FUNC GstUri * gst_uri_ref (GstUri * uri);
#endif
static inline GstUri *
gst_uri_ref (GstUri * uri)
{
return GST_URI_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (uri)));
}
/**
* gst_uri_unref:
* @uri: (transfer full): This #GstUri object.
*
* Decrement the reference count to this #GstUri object.
*
* If the reference count drops to 0 then finalize this object.
*
* See gst_mini_object_unref() for further info.
*/
#ifdef _FOOL_GTK_DOC_
G_INLINE_FUNC void gst_uri_unref (GstUri * uri);
#endif
static inline void
gst_uri_unref (GstUri * uri)
{
gst_mini_object_unref (GST_MINI_OBJECT_CAST (uri));
}
G_END_DECLS
#endif /* __GST_URI_H__ */

View file

@ -164,6 +164,594 @@ GST_START_TEST (test_element_make_from_uri)
GST_END_TEST;
GST_START_TEST (test_url_parsing)
{
GstUri *url;
GList *list;
gchar *tmp_str;
url =
gst_uri_from_string
("scheme://user:pass@host.com:1234/path/to/item-obj?query=something#fragment");
fail_unless_equals_string (gst_uri_get_scheme (url), "scheme");
fail_unless_equals_string (gst_uri_get_userinfo (url), "user:pass");
fail_unless_equals_string (gst_uri_get_host (url), "host.com");
fail_unless (gst_uri_get_port (url) == 1234);
tmp_str = gst_uri_get_path (url);
fail_unless_equals_string (tmp_str, "/path/to/item-obj");
g_free (tmp_str);
list = gst_uri_get_query_keys (url);
fail_unless (g_list_length (list) == 1);
g_list_free (list);
fail_unless (gst_uri_query_has_key (url, "query"));
fail_unless_equals_string (gst_uri_get_query_value (url, "query"),
"something");
fail_unless_equals_string (gst_uri_get_fragment (url), "fragment");
gst_uri_unref (url);
url = gst_uri_from_string ("scheme://host/path/to/dir/");
fail_unless_equals_string (gst_uri_get_scheme (url), "scheme");
fail_unless (gst_uri_get_userinfo (url) == NULL);
fail_unless_equals_string (gst_uri_get_host (url), "host");
fail_unless (gst_uri_get_port (url) == GST_URI_NO_PORT);
tmp_str = gst_uri_get_path (url);
fail_unless_equals_string (tmp_str, "/path/to/dir/");
g_free (tmp_str);
fail_unless (gst_uri_get_query_table (url) == NULL);
fail_unless (gst_uri_get_fragment (url) == NULL);
gst_uri_unref (url);
url = gst_uri_from_string ("urn:name:path");
fail_unless_equals_string (gst_uri_get_scheme (url), "urn");
fail_unless (gst_uri_get_userinfo (url) == NULL);
fail_unless (gst_uri_get_host (url) == NULL);
fail_unless (gst_uri_get_port (url) == GST_URI_NO_PORT);
tmp_str = gst_uri_get_path (url);
fail_unless_equals_string (tmp_str, "name:path");
g_free (tmp_str);
list = gst_uri_get_query_keys (url);
fail_unless (g_list_length (list) == 0);
g_list_free (list);
fail_unless (gst_uri_get_fragment (url) == NULL);
gst_uri_unref (url);
}
GST_END_TEST;
GST_START_TEST (test_url_normalization)
{
GstUri *url;
gchar *tmp_str;
url =
gst_uri_from_string
("ScHeMe://User:P%61ss@HOST.%63om:1234/path/./from/../to%7d/item%2dobj?qu%65ry=something#fr%61gment");
fail_unless (gst_uri_normalize (url));
fail_unless_equals_string (gst_uri_get_scheme (url), "scheme");
fail_unless_equals_string (gst_uri_get_userinfo (url), "User:Pass");
fail_unless_equals_string (gst_uri_get_host (url), "host.com");
tmp_str = gst_uri_get_path (url);
fail_unless_equals_string (tmp_str, "/path/to}/item-obj");
g_free (tmp_str);
fail_unless (gst_uri_query_has_key (url, "query"));
fail_unless_equals_string (gst_uri_get_query_value (url, "query"),
"something");
fail_unless_equals_string (gst_uri_get_fragment (url), "fragment");
gst_uri_unref (url);
}
GST_END_TEST;
GST_START_TEST (test_url_joining)
{
GstUri *base, *rel, *joined;
gchar *l;
base =
gst_uri_from_string
("http://example.com/path/to/dir/filename.html#fragment");
/* test change of fragment only */
rel = gst_uri_from_string ("#new_frag");
joined = gst_uri_join (base, rel);
l = gst_uri_to_string (joined);
fail_unless_equals_string (l,
"http://example.com/path/to/dir/filename.html#new_frag");
g_free (l);
gst_uri_unref (joined);
gst_uri_unref (rel);
/* test addition of new query string */
rel = gst_uri_from_string ("?key=val");
joined = gst_uri_join (base, rel);
l = gst_uri_to_string (joined);
fail_unless_equals_string (l,
"http://example.com/path/to/dir/filename.html?key=val");
g_free (l);
gst_uri_unref (joined);
gst_uri_unref (rel);
/* test new base filename */
rel = gst_uri_from_string ("new_filename.xml");
joined = gst_uri_join (base, rel);
l = gst_uri_to_string (joined);
fail_unless_equals_string (l,
"http://example.com/path/to/dir/new_filename.xml");
g_free (l);
gst_uri_unref (joined);
gst_uri_unref (rel);
/* test relative file same directory */
rel = gst_uri_from_string ("./new_filename.xml");
joined = gst_uri_join (base, rel);
l = gst_uri_to_string (joined);
fail_unless_equals_string (l,
"http://example.com/path/to/dir/new_filename.xml");
g_free (l);
gst_uri_unref (joined);
gst_uri_unref (rel);
/* test relative file parent directory */
rel = gst_uri_from_string ("../new_filename.xml");
joined = gst_uri_join (base, rel);
l = gst_uri_to_string (joined);
fail_unless_equals_string (l, "http://example.com/path/to/new_filename.xml");
g_free (l);
gst_uri_unref (joined);
gst_uri_unref (rel);
/* test relative file grandparent directory */
rel = gst_uri_from_string ("../../new_filename.xml");
joined = gst_uri_join (base, rel);
l = gst_uri_to_string (joined);
fail_unless_equals_string (l, "http://example.com/path/new_filename.xml");
g_free (l);
gst_uri_unref (joined);
gst_uri_unref (rel);
/* test relative file root directory */
rel = gst_uri_from_string ("../../../new_filename.xml");
joined = gst_uri_join (base, rel);
l = gst_uri_to_string (joined);
fail_unless_equals_string (l, "http://example.com/new_filename.xml");
g_free (l);
gst_uri_unref (joined);
gst_uri_unref (rel);
/* test relative file beyond root directory */
rel = gst_uri_from_string ("../../../../new_filename.xml");
joined = gst_uri_join (base, rel);
l = gst_uri_to_string (joined);
fail_unless_equals_string (l, "http://example.com/new_filename.xml");
g_free (l);
gst_uri_unref (joined);
gst_uri_unref (rel);
/* test add subdirectory */
rel = gst_uri_from_string ("subdir/new_filename.xml");
joined = gst_uri_join (base, rel);
l = gst_uri_to_string (joined);
fail_unless_equals_string (l,
"http://example.com/path/to/dir/subdir/new_filename.xml");
g_free (l);
gst_uri_unref (joined);
gst_uri_unref (rel);
/* test change directory */
rel = gst_uri_from_string ("../subdir/new_filename.xml");
joined = gst_uri_join (base, rel);
l = gst_uri_to_string (joined);
fail_unless_equals_string (l,
"http://example.com/path/to/subdir/new_filename.xml");
g_free (l);
gst_uri_unref (joined);
gst_uri_unref (rel);
gst_uri_unref (base);
/* change base for path ending in directory */
base = gst_uri_from_string ("http://example.com/path/to/dir/");
/* test adding file to directory */
rel = gst_uri_from_string ("new_filename.xml");
joined = gst_uri_join (base, rel);
l = gst_uri_to_string (joined);
fail_unless_equals_string (l,
"http://example.com/path/to/dir/new_filename.xml");
g_free (l);
gst_uri_unref (joined);
gst_uri_unref (rel);
/* test adding file to directory using relative path */
rel = gst_uri_from_string ("./new_filename.xml");
joined = gst_uri_join (base, rel);
l = gst_uri_to_string (joined);
fail_unless_equals_string (l,
"http://example.com/path/to/dir/new_filename.xml");
g_free (l);
gst_uri_unref (joined);
gst_uri_unref (rel);
/* test filename in parent directory */
rel = gst_uri_from_string ("../new_filename.xml");
joined = gst_uri_join (base, rel);
l = gst_uri_to_string (joined);
fail_unless_equals_string (l, "http://example.com/path/to/new_filename.xml");
g_free (l);
gst_uri_unref (joined);
gst_uri_unref (rel);
/* test replace with absolute */
rel = gst_uri_from_string ("https://ssl.example.com/new_filename.xml");
joined = gst_uri_join (base, rel);
l = gst_uri_to_string (joined);
fail_unless_equals_string (l, "https://ssl.example.com/new_filename.xml");
g_free (l);
gst_uri_unref (joined);
gst_uri_unref (rel);
gst_uri_unref (base);
}
GST_END_TEST;
GST_START_TEST (test_url_equality)
{
GstUri *url1, *url2;
url1 =
gst_uri_from_string
("ScHeMe://User:Pass@HOST.com:1234/path/./from/../to%7d/item%2dobj?query=something#fragment");
/* equal */
url2 =
gst_uri_from_string
("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
fail_unless (gst_uri_equal (url1, url2));
fail_unless (gst_uri_equal (url2, url1));
gst_uri_unref (url2);
/* different fragment */
url2 =
gst_uri_from_string
("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something#different-fragment");
fail_unless (!gst_uri_equal (url1, url2));
gst_uri_unref (url2);
/* different query */
url2 =
gst_uri_from_string
("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=different-something#fragment");
fail_unless (!gst_uri_equal (url1, url2));
gst_uri_unref (url2);
/* different path */
url2 =
gst_uri_from_string
("scheme://User:Pass@host.com:1234/path/to%7D/different-item-obj?query=something#fragment");
fail_unless (!gst_uri_equal (url1, url2));
gst_uri_unref (url2);
/* different port */
url2 =
gst_uri_from_string
("scheme://User:Pass@host.com:4321/path/to%7D/item-obj?query=something#fragment");
fail_unless (!gst_uri_equal (url1, url2));
gst_uri_unref (url2);
/* different host */
url2 =
gst_uri_from_string
("scheme://User:Pass@different-host.com:1234/path/to%7D/item-obj?query=something#fragment");
fail_unless (!gst_uri_equal (url1, url2));
gst_uri_unref (url2);
/* different userinfo */
url2 =
gst_uri_from_string
("scheme://Different-User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
fail_unless (!gst_uri_equal (url1, url2));
gst_uri_unref (url2);
/* different scheme */
url2 =
gst_uri_from_string
("different+scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
fail_unless (!gst_uri_equal (url1, url2));
gst_uri_unref (url2);
/* different (no scheme) */
url2 =
gst_uri_from_string
("//User:Pass@host.com:1234/path/to%7D/item-obj?query=something#fragment");
fail_unless (!gst_uri_equal (url1, url2));
gst_uri_unref (url2);
/* different (no userinfo) */
url2 =
gst_uri_from_string
("scheme://host.com:1234/path/to%7D/item-obj?query=something#fragment");
fail_unless (!gst_uri_equal (url1, url2));
gst_uri_unref (url2);
/* different (no host) */
url2 =
gst_uri_from_string
("scheme://User:Pass@:1234/path/to%7D/item-obj?query=something#fragment");
fail_unless (!gst_uri_equal (url1, url2));
gst_uri_unref (url2);
/* different (no port) */
url2 =
gst_uri_from_string
("scheme://User:Pass@host.com/path/to%7D/item-obj?query=something#fragment");
fail_unless (!gst_uri_equal (url1, url2));
gst_uri_unref (url2);
/* different (no path) */
url2 =
gst_uri_from_string
("scheme://User:Pass@host.com:1234?query=something#fragment");
fail_unless (!gst_uri_equal (url1, url2));
gst_uri_unref (url2);
/* different (no query) */
url2 =
gst_uri_from_string
("scheme://User:Pass@host.com:1234/path/to%7D/item-obj#fragment");
fail_unless (!gst_uri_equal (url1, url2));
gst_uri_unref (url2);
/* different (no fragment) */
url2 =
gst_uri_from_string
("scheme://User:Pass@host.com:1234/path/to%7D/item-obj?query=something");
fail_unless (!gst_uri_equal (url1, url2));
gst_uri_unref (url2);
/* compare two NULL uris */
fail_unless (gst_uri_equal (NULL, NULL));
/* compare same object */
fail_unless (gst_uri_equal (url1, url1));
/* compare one NULL and one non-NULL uri */
fail_unless (!gst_uri_equal (url1, NULL));
fail_unless (!gst_uri_equal (NULL, url1));
gst_uri_unref (url1);
}
GST_END_TEST;
GST_START_TEST (test_url_constructors)
{
GstUri *url1, *url2;
gchar *tmp_str;
GHashTable *tmp_table;
url1 =
gst_uri_new ("scheme", "userinfo", "hostname", 1234, "/path/to/file",
"query", "fragment");
fail_unless_equals_string (gst_uri_get_scheme (url1), "scheme");
fail_unless_equals_string (gst_uri_get_userinfo (url1), "userinfo");
fail_unless_equals_string (gst_uri_get_host (url1), "hostname");
fail_unless (gst_uri_get_port (url1) == 1234);
tmp_str = gst_uri_get_path (url1);
fail_unless_equals_string (tmp_str, "/path/to/file");
g_free (tmp_str);
tmp_table = gst_uri_get_query_table (url1);
fail_unless (g_hash_table_size (tmp_table) == 1);
fail_unless (g_hash_table_contains (tmp_table, "query"));
fail_unless (g_hash_table_lookup (tmp_table, "query") == NULL);
g_hash_table_unref (tmp_table);
fail_unless_equals_string (gst_uri_get_fragment (url1), "fragment");
tmp_str = gst_uri_to_string (url1);
fail_unless_equals_string (tmp_str,
"scheme://userinfo@hostname:1234/path/to/file?query#fragment");
g_free (tmp_str);
url2 =
gst_uri_new_with_base (url1, NULL, NULL, NULL, GST_URI_NO_PORT,
"new_file", NULL, NULL);
fail_unless_equals_string (gst_uri_get_scheme (url2), "scheme");
fail_unless_equals_string (gst_uri_get_userinfo (url2), "userinfo");
fail_unless_equals_string (gst_uri_get_host (url2), "hostname");
fail_unless (gst_uri_get_port (url2) == 1234);
tmp_str = gst_uri_get_path (url2);
fail_unless_equals_string (tmp_str, "/path/to/new_file");
g_free (tmp_str);
fail_unless (gst_uri_get_query_table (url2) == NULL);
fail_unless (gst_uri_get_fragment (url2) == NULL);
tmp_str = gst_uri_to_string (url2);
fail_unless_equals_string (tmp_str,
"scheme://userinfo@hostname:1234/path/to/new_file");
g_free (tmp_str);
gst_uri_unref (url2);
url2 = gst_uri_from_string_with_base (url1, "/a/new/path/to/file");
fail_unless_equals_string (gst_uri_get_scheme (url2), "scheme");
fail_unless_equals_string (gst_uri_get_userinfo (url2), "userinfo");
fail_unless_equals_string (gst_uri_get_host (url2), "hostname");
fail_unless (gst_uri_get_port (url2) == 1234);
tmp_str = gst_uri_get_path (url2);
fail_unless_equals_string (tmp_str, "/a/new/path/to/file");
g_free (tmp_str);
fail_unless (gst_uri_get_query_table (url2) == NULL);
fail_unless (gst_uri_get_fragment (url2) == NULL);
tmp_str = gst_uri_to_string (url2);
fail_unless_equals_string (tmp_str,
"scheme://userinfo@hostname:1234/a/new/path/to/file");
g_free (tmp_str);
gst_uri_unref (url2);
url2 = gst_uri_copy (url1);
fail_unless (gst_uri_equal (url1, url2));
gst_uri_set_query_value (url2, "key", "value");
fail_unless (!gst_uri_equal (url1, url2));
gst_uri_unref (url2);
gst_uri_unref (url1);
}
GST_END_TEST;
GST_START_TEST (test_url_get_set)
{
GstUri *url;
gchar *tmp_str;
GList *tmp_list;
url = gst_uri_from_string ("scheme://hostname/path/to/file?query#fragment");
fail_unless (gst_uri_set_scheme (url, "new+scheme"));
fail_unless_equals_string (gst_uri_get_scheme (url), "new+scheme");
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str,
"new+scheme://hostname/path/to/file?query#fragment");
g_free (tmp_str);
fail_unless (gst_uri_set_scheme (url, NULL));
fail_unless (gst_uri_get_scheme (url) == NULL);
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str, "//hostname/path/to/file?query#fragment");
g_free (tmp_str);
fail_unless (!gst_uri_set_scheme (NULL, "fail"));
fail_unless (gst_uri_set_scheme (NULL, NULL));
fail_unless (gst_uri_set_userinfo (url, "username:password"));
fail_unless_equals_string (gst_uri_get_userinfo (url), "username:password");
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str,
"//username:password@hostname/path/to/file?query#fragment");
g_free (tmp_str);
fail_unless (gst_uri_set_userinfo (url, NULL));
fail_unless (gst_uri_get_userinfo (url) == NULL);
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str, "//hostname/path/to/file?query#fragment");
g_free (tmp_str);
fail_unless (!gst_uri_set_userinfo (NULL, "fail"));
fail_unless (gst_uri_set_userinfo (NULL, NULL));
fail_unless (gst_uri_set_host (url, NULL));
fail_unless (gst_uri_get_host (url) == NULL);
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str, "/path/to/file?query#fragment");
g_free (tmp_str);
fail_unless (gst_uri_set_host (url, "example.com"));
fail_unless_equals_string (gst_uri_get_host (url), "example.com");
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str,
"//example.com/path/to/file?query#fragment");
g_free (tmp_str);
fail_unless (!gst_uri_set_host (NULL, "fail"));
fail_unless (gst_uri_set_host (NULL, NULL));
fail_unless (gst_uri_set_port (url, 12345));
fail_unless (gst_uri_get_port (url) == 12345);
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str,
"//example.com:12345/path/to/file?query#fragment");
g_free (tmp_str);
fail_unless (gst_uri_set_port (url, GST_URI_NO_PORT));
fail_unless (gst_uri_get_port (url) == GST_URI_NO_PORT);
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str,
"//example.com/path/to/file?query#fragment");
g_free (tmp_str);
fail_unless (!gst_uri_set_port (NULL, 1234));
fail_unless (gst_uri_set_port (NULL, GST_URI_NO_PORT));
fail_unless (gst_uri_append_path_segment (url, "here"));
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str,
"//example.com/path/to/file/here?query#fragment");
g_free (tmp_str);
fail_unless (!gst_uri_append_path_segment (NULL, "fail"));
fail_unless (gst_uri_append_path_segment (NULL, NULL));
fail_unless (gst_uri_append_path (url, "../there"));
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str,
"//example.com/path/to/file/here/../there?query#fragment");
g_free (tmp_str);
fail_unless (!gst_uri_append_path (NULL, "fail"));
fail_unless (gst_uri_append_path (NULL, NULL));
gst_uri_normalize (url);
tmp_list = gst_uri_get_path_segments (url);
fail_unless (tmp_list != NULL);
tmp_list = g_list_append (tmp_list, g_strdup ("segment"));
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str,
"//example.com/path/to/file/there?query#fragment");
g_free (tmp_str);
fail_unless (gst_uri_set_path_segments (url, tmp_list));
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str,
"//example.com/path/to/file/there/segment?query#fragment");
g_free (tmp_str);
tmp_list = g_list_append (NULL, g_strdup ("test"));
fail_unless (!gst_uri_set_path_segments (NULL, tmp_list));
fail_unless (gst_uri_set_path_segments (NULL, NULL));
fail_unless (gst_uri_set_query_value (url, "key", "value"));
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str,
"//example.com/path/to/file/there/segment?query&key=value#fragment");
g_free (tmp_str);
fail_unless (gst_uri_set_query_value (url, "key", NULL));
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str,
"//example.com/path/to/file/there/segment?query&key#fragment");
g_free (tmp_str);
fail_unless (!gst_uri_set_query_value (NULL, "key", "value"));
fail_unless (gst_uri_remove_query_key (url, "key"));
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str,
"//example.com/path/to/file/there/segment?query#fragment");
g_free (tmp_str);
fail_unless (!gst_uri_remove_query_key (url, "key"));
fail_unless (!gst_uri_remove_query_key (NULL, "key"));
fail_unless (gst_uri_set_fragment (url, NULL));
fail_unless (gst_uri_get_fragment (url) == NULL);
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str,
"//example.com/path/to/file/there/segment?query");
g_free (tmp_str);
fail_unless (gst_uri_set_fragment (url, "tag"));
fail_unless_equals_string (gst_uri_get_fragment (url), "tag");
tmp_str = gst_uri_to_string (url);
fail_unless_equals_string (tmp_str,
"//example.com/path/to/file/there/segment?query#tag");
g_free (tmp_str);
fail_unless (!gst_uri_set_fragment (NULL, "can't set if no URI"));
fail_unless (gst_uri_set_fragment (NULL, NULL));
gst_uri_unref (url);
}
GST_END_TEST;
static Suite *
gst_uri_suite (void)
{
@ -180,6 +768,12 @@ gst_uri_suite (void)
#ifdef G_OS_WIN32
tcase_add_test (tc_chain, test_win32_uri);
#endif
tcase_add_test (tc_chain, test_url_parsing);
tcase_add_test (tc_chain, test_url_normalization);
tcase_add_test (tc_chain, test_url_joining);
tcase_add_test (tc_chain, test_url_equality);
tcase_add_test (tc_chain, test_url_constructors);
tcase_add_test (tc_chain, test_url_get_set);
return s;
}

View file

@ -1345,20 +1345,60 @@ EXPORTS
gst_type_find_suggest
gst_type_find_suggest_simple
gst_update_registry
gst_uri_append_path
gst_uri_append_path_segment
gst_uri_construct
gst_uri_equal
gst_uri_error_get_type
gst_uri_error_quark
gst_uri_from_string
gst_uri_from_string_with_base
gst_uri_get_fragment
gst_uri_get_host
gst_uri_get_location
gst_uri_get_path
gst_uri_get_path_segments
gst_uri_get_path_string
gst_uri_get_port
gst_uri_get_protocol
gst_uri_get_query_keys
gst_uri_get_query_string
gst_uri_get_query_table
gst_uri_get_query_value
gst_uri_get_scheme
gst_uri_get_type
gst_uri_get_userinfo
gst_uri_handler_get_protocols
gst_uri_handler_get_type
gst_uri_handler_get_uri
gst_uri_handler_get_uri_type
gst_uri_handler_set_uri
gst_uri_has_protocol
gst_uri_is_normalized
gst_uri_is_valid
gst_uri_is_writable
gst_uri_join
gst_uri_join_strings
gst_uri_make_writable
gst_uri_new
gst_uri_new_with_base
gst_uri_normalize
gst_uri_protocol_is_supported
gst_uri_protocol_is_valid
gst_uri_query_has_key
gst_uri_remove_query_key
gst_uri_set_fragment
gst_uri_set_host
gst_uri_set_path
gst_uri_set_path_segments
gst_uri_set_path_string
gst_uri_set_port
gst_uri_set_query_string
gst_uri_set_query_table
gst_uri_set_query_value
gst_uri_set_scheme
gst_uri_set_userinfo
gst_uri_to_string
gst_uri_type_get_type
gst_util_array_binary_search
gst_util_double_to_fraction