From: Sebastian Dröge Date: Mon, 28 Apr 2014 07:23:34 +0000 (+0200) Subject: uridownloader: Add API to specify the referer of a request X-Git-Tag: 1.19.3~507^2~11306 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fbbe73a62ee6ed7ec7c36187a6dd4cff92a1804a;p=platform%2Fupstream%2Fgstreamer.git uridownloader: Add API to specify the referer of a request --- diff --git a/gst-libs/gst/uridownloader/gsturidownloader.c b/gst-libs/gst/uridownloader/gsturidownloader.c index 69dd92b..8614c44 100644 --- a/gst-libs/gst/uridownloader/gsturidownloader.c +++ b/gst-libs/gst/uridownloader/gsturidownloader.c @@ -323,7 +323,7 @@ gst_uri_downloader_set_range (GstUriDownloader * downloader, static gboolean gst_uri_downloader_set_uri (GstUriDownloader * downloader, const gchar * uri, - gboolean compress) + const gchar * referer, gboolean compress) { GstPad *pad; GObjectClass *gobject_class; @@ -378,6 +378,15 @@ gst_uri_downloader_set_uri (GstUriDownloader * downloader, const gchar * uri, g_object_set (downloader->priv->urisrc, "compress", compress, NULL); if (g_object_class_find_property (gobject_class, "keep-alive")) g_object_set (downloader->priv->urisrc, "keep-alive", TRUE, NULL); + if (referer && g_object_class_find_property (gobject_class, "extra-headers")) { + GstStructure *extra_headers = + gst_structure_new ("headers", "Referer", G_TYPE_STRING, referer, NULL); + + g_object_set (downloader->priv->urisrc, "extra-headers", extra_headers, + NULL); + + gst_structure_free (extra_headers); + } /* add a sync handler for the bus messages to detect errors in the download */ gst_element_set_bus (GST_ELEMENT (downloader->priv->urisrc), @@ -397,12 +406,29 @@ GstFragment * gst_uri_downloader_fetch_uri (GstUriDownloader * downloader, const gchar * uri, gboolean compress, GError ** err) { - return gst_uri_downloader_fetch_uri_with_range (downloader, uri, compress, 0, - -1, err); + return gst_uri_downloader_fetch_uri_with_range_and_referer (downloader, uri, + NULL, compress, 0, -1, err); +} + +GstFragment * +gst_uri_downloader_fetch_uri_with_referer (GstUriDownloader * downloader, + const gchar * uri, const gchar * referer, gboolean compress, GError ** err) +{ + return gst_uri_downloader_fetch_uri_with_range_and_referer (downloader, uri, + referer, compress, 0, -1, err); +} + +GstFragment * +gst_uri_downloader_fetch_uri_with_range (GstUriDownloader * downloader, + const gchar * uri, gboolean compress, gint64 range_start, gint64 range_end, + GError ** err) +{ + return gst_uri_downloader_fetch_uri_with_range_and_referer (downloader, uri, + NULL, compress, range_start, range_end, err); } /** - * gst_uri_downloader_fetch_uri_with_range: + * gst_uri_downloader_fetch_uri_with_range_and_referer: * @downloader: the #GstUriDownloader * @uri: the uri * @range_start: the starting byte index @@ -411,9 +437,9 @@ gst_uri_downloader_fetch_uri (GstUriDownloader * downloader, const gchar * uri, * Returns the downloaded #GstFragment */ GstFragment * -gst_uri_downloader_fetch_uri_with_range (GstUriDownloader * downloader, - const gchar * uri, gboolean compress, gint64 range_start, - gint64 range_end, GError ** err) +gst_uri_downloader_fetch_uri_with_range_and_referer (GstUriDownloader * + downloader, const gchar * uri, const gchar * referer, gboolean compress, + gint64 range_start, gint64 range_end, GError ** err) { GstStateChangeReturn ret; GstFragment *download = NULL; @@ -430,7 +456,7 @@ gst_uri_downloader_fetch_uri_with_range (GstUriDownloader * downloader, goto quit; } - if (!gst_uri_downloader_set_uri (downloader, uri, compress)) { + if (!gst_uri_downloader_set_uri (downloader, uri, referer, compress)) { GST_WARNING_OBJECT (downloader, "Failed to set URI"); goto quit; } diff --git a/gst-libs/gst/uridownloader/gsturidownloader.h b/gst-libs/gst/uridownloader/gsturidownloader.h index 3a9184e..e35aee2 100644 --- a/gst-libs/gst/uridownloader/gsturidownloader.h +++ b/gst-libs/gst/uridownloader/gsturidownloader.h @@ -58,6 +58,8 @@ GType gst_uri_downloader_get_type (void); GstUriDownloader * gst_uri_downloader_new (void); GstFragment * gst_uri_downloader_fetch_uri (GstUriDownloader * downloader, const gchar * uri, gboolean compress, GError ** err); GstFragment * gst_uri_downloader_fetch_uri_with_range (GstUriDownloader * downloader, const gchar * uri, gboolean compress, gint64 range_start, gint64 range_end, GError ** err); +GstFragment * gst_uri_downloader_fetch_uri_with_referer (GstUriDownloader * downloader, const gchar * uri, const gchar * referer, gboolean compress, GError ** err); +GstFragment * gst_uri_downloader_fetch_uri_with_range_and_referer (GstUriDownloader * downloader, const gchar * uri, const gchar * referer, gboolean compress, gint64 range_start, gint64 range_end, GError ** err); void gst_uri_downloader_reset (GstUriDownloader *downloader); void gst_uri_downloader_cancel (GstUriDownloader *downloader); void gst_uri_downloader_free (GstUriDownloader *downloader);