souphttpsrc: add cookie jar
[platform/upstream/gst-plugins-good.git] / ext / soup / gstsouphttpsrc.c
1 /* GStreamer
2  * Copyright (C) 2007-2008 Wouter Cloetens <wouter@mind.be>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more
13  */
14
15 /**
16  * SECTION:element-souphttpsrc
17  *
18  * This plugin reads data from a remote location specified by a URI.
19  * Supported protocols are 'http', 'https'.
20  *
21  * An HTTP proxy must be specified by its URL.
22  * If the "http_proxy" environment variable is set, its value is used.
23  * If built with libsoup's GNOME integration features, the GNOME proxy
24  * configuration will be used, or failing that, proxy autodetection.
25  * The #GstSoupHTTPSrc:proxy property can be used to override the default.
26  *
27  * In case the #GstSoupHTTPSrc:iradio-mode property is set and the location is
28  * an HTTP resource, souphttpsrc will send special Icecast HTTP headers to the
29  * server to request additional Icecast meta-information.
30  * If the server is not an Icecast server, it will behave as if the
31  * #GstSoupHTTPSrc:iradio-mode property were not set. If it is, souphttpsrc will
32  * output data with a media type of application/x-icy, in which case you will
33  * need to use the #ICYDemux element as follow-up element to extract the Icecast
34  * metadata and to determine the underlying media type.
35  *
36  * <refsect2>
37  * <title>Example launch line</title>
38  * |[
39  * gst-launch-1.0 -v souphttpsrc location=https://some.server.org/index.html
40  *     ! filesink location=/home/joe/server.html
41  * ]| The above pipeline reads a web page from a server using the HTTPS protocol
42  * and writes it to a local file.
43  * |[
44  * gst-launch-1.0 -v souphttpsrc user-agent="FooPlayer 0.99 beta"
45  *     automatic-redirect=false proxy=http://proxy.intranet.local:8080
46  *     location=http://music.foobar.com/demo.mp3 ! mad ! audioconvert
47  *     ! audioresample ! alsasink
48  * ]| The above pipeline will read and decode and play an mp3 file from a
49  * web server using the HTTP protocol. If the server sends redirects,
50  * the request fails instead of following the redirect. The specified
51  * HTTP proxy server is used. The User-Agent HTTP request header
52  * is set to a custom string instead of "GStreamer souphttpsrc."
53  * |[
54  * gst-launch-1.0 -v souphttpsrc location=http://10.11.12.13/mjpeg
55  *     do-timestamp=true ! multipartdemux
56  *     ! image/jpeg,width=640,height=480 ! matroskamux
57  *     ! filesink location=mjpeg.mkv
58  * ]| The above pipeline reads a motion JPEG stream from an IP camera
59  * using the HTTP protocol, encoded as mime/multipart image/jpeg
60  * parts, and writes a Matroska motion JPEG file. The width and
61  * height properties are set in the caps to provide the Matroska
62  * multiplexer with the information to set this in the header.
63  * Timestamps are set on the buffers as they arrive from the camera.
64  * These are used by the mime/multipart demultiplexer to emit timestamps
65  * on the JPEG-encoded video frame buffers. This allows the Matroska
66  * multiplexer to timestamp the frames in the resulting file.
67  * </refsect2>
68  */
69
70 #ifdef HAVE_CONFIG_H
71 #include "config.h"
72 #endif
73
74 #include <string.h>
75 #ifdef HAVE_STDLIB_H
76 #include <stdlib.h>             /* atoi() */
77 #endif
78 #include <gst/gstelement.h>
79 #include <gst/gst-i18n-plugin.h>
80 #include <libsoup/soup.h>
81 #include "gstsouphttpsrc.h"
82 #include "gstsouputils.h"
83
84 /* libsoup before 2.47.0 was stealing our main context from us,
85  * so we can't reliable use it to clean up all pending resources
86  * once we're done... let's just continue leaking on old versions.
87  * https://bugzilla.gnome.org/show_bug.cgi?id=663944
88  */
89 #if defined(SOUP_MINOR_VERSION) && SOUP_MINOR_VERSION >= 47
90 #define LIBSOUP_DOES_NOT_STEAL_OUR_CONTEXT 1
91 #endif
92
93 #include <gst/tag/tag.h>
94
95 GST_DEBUG_CATEGORY_STATIC (souphttpsrc_debug);
96 #define GST_CAT_DEFAULT souphttpsrc_debug
97
98 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
99     GST_PAD_SRC,
100     GST_PAD_ALWAYS,
101     GST_STATIC_CAPS_ANY);
102
103 enum
104 {
105   PROP_0,
106   PROP_LOCATION,
107   PROP_IS_LIVE,
108   PROP_USER_AGENT,
109   PROP_AUTOMATIC_REDIRECT,
110   PROP_PROXY,
111   PROP_USER_ID,
112   PROP_USER_PW,
113   PROP_PROXY_ID,
114   PROP_PROXY_PW,
115   PROP_COOKIES,
116   PROP_IRADIO_MODE,
117   PROP_TIMEOUT,
118   PROP_EXTRA_HEADERS,
119   PROP_SOUP_LOG_LEVEL,
120   PROP_COMPRESS,
121   PROP_KEEP_ALIVE,
122   PROP_SSL_STRICT,
123   PROP_SSL_CA_FILE,
124   PROP_SSL_USE_SYSTEM_CA_FILE,
125   PROP_TLS_DATABASE,
126   PROP_RETRIES,
127   PROP_METHOD
128 };
129
130 #define DEFAULT_USER_AGENT           "GStreamer souphttpsrc "
131 #define DEFAULT_IRADIO_MODE          TRUE
132 #define DEFAULT_SOUP_LOG_LEVEL       SOUP_LOGGER_LOG_HEADERS
133 #define DEFAULT_COMPRESS             FALSE
134 #define DEFAULT_KEEP_ALIVE           FALSE
135 #define DEFAULT_SSL_STRICT           TRUE
136 #define DEFAULT_SSL_CA_FILE          NULL
137 #define DEFAULT_SSL_USE_SYSTEM_CA_FILE TRUE
138 #define DEFAULT_TLS_DATABASE         NULL
139 #define DEFAULT_TIMEOUT              15
140 #define DEFAULT_RETRIES              3
141 #define DEFAULT_SOUP_METHOD          NULL
142
143 static void gst_soup_http_src_uri_handler_init (gpointer g_iface,
144     gpointer iface_data);
145 static void gst_soup_http_src_finalize (GObject * gobject);
146 static void gst_soup_http_src_dispose (GObject * gobject);
147
148 static void gst_soup_http_src_set_property (GObject * object, guint prop_id,
149     const GValue * value, GParamSpec * pspec);
150 static void gst_soup_http_src_get_property (GObject * object, guint prop_id,
151     GValue * value, GParamSpec * pspec);
152
153 static GstStateChangeReturn gst_soup_http_src_change_state (GstElement *
154     element, GstStateChange transition);
155 static GstFlowReturn gst_soup_http_src_create (GstPushSrc * psrc,
156     GstBuffer ** outbuf);
157 static gboolean gst_soup_http_src_start (GstBaseSrc * bsrc);
158 static gboolean gst_soup_http_src_stop (GstBaseSrc * bsrc);
159 static gboolean gst_soup_http_src_get_size (GstBaseSrc * bsrc, guint64 * size);
160 static gboolean gst_soup_http_src_is_seekable (GstBaseSrc * bsrc);
161 static gboolean gst_soup_http_src_do_seek (GstBaseSrc * bsrc,
162     GstSegment * segment);
163 static gboolean gst_soup_http_src_query (GstBaseSrc * bsrc, GstQuery * query);
164 static gboolean gst_soup_http_src_unlock (GstBaseSrc * bsrc);
165 static gboolean gst_soup_http_src_unlock_stop (GstBaseSrc * bsrc);
166 static gboolean gst_soup_http_src_set_location (GstSoupHTTPSrc * src,
167     const gchar * uri, GError ** error);
168 static gboolean gst_soup_http_src_set_proxy (GstSoupHTTPSrc * src,
169     const gchar * uri);
170 static char *gst_soup_http_src_unicodify (const char *str);
171 static gboolean gst_soup_http_src_build_message (GstSoupHTTPSrc * src,
172     const gchar * method);
173 static void gst_soup_http_src_cancel_message (GstSoupHTTPSrc * src);
174 static void gst_soup_http_src_queue_message (GstSoupHTTPSrc * src);
175 static gboolean gst_soup_http_src_add_range_header (GstSoupHTTPSrc * src,
176     guint64 offset, guint64 stop_offset);
177 static void gst_soup_http_src_session_unpause_message (GstSoupHTTPSrc * src);
178 static void gst_soup_http_src_session_pause_message (GstSoupHTTPSrc * src);
179 static gboolean gst_soup_http_src_session_open (GstSoupHTTPSrc * src);
180 static void gst_soup_http_src_session_close (GstSoupHTTPSrc * src);
181 static void gst_soup_http_src_parse_status (SoupMessage * msg,
182     GstSoupHTTPSrc * src);
183 static void gst_soup_http_src_chunk_free (gpointer gstbuf);
184 static SoupBuffer *gst_soup_http_src_chunk_allocator (SoupMessage * msg,
185     gsize max_len, gpointer user_data);
186 static void gst_soup_http_src_got_chunk_cb (SoupMessage * msg,
187     SoupBuffer * chunk, GstSoupHTTPSrc * src);
188 static void gst_soup_http_src_response_cb (SoupSession * session,
189     SoupMessage * msg, GstSoupHTTPSrc * src);
190 static void gst_soup_http_src_got_headers_cb (SoupMessage * msg,
191     GstSoupHTTPSrc * src);
192 static void gst_soup_http_src_got_body_cb (SoupMessage * msg,
193     GstSoupHTTPSrc * src);
194 static void gst_soup_http_src_finished_cb (SoupMessage * msg,
195     GstSoupHTTPSrc * src);
196 static void gst_soup_http_src_authenticate_cb (SoupSession * session,
197     SoupMessage * msg, SoupAuth * auth, gboolean retrying,
198     GstSoupHTTPSrc * src);
199
200 #define gst_soup_http_src_parent_class parent_class
201 G_DEFINE_TYPE_WITH_CODE (GstSoupHTTPSrc, gst_soup_http_src, GST_TYPE_PUSH_SRC,
202     G_IMPLEMENT_INTERFACE (GST_TYPE_URI_HANDLER,
203         gst_soup_http_src_uri_handler_init));
204
205 static void
206 gst_soup_http_src_class_init (GstSoupHTTPSrcClass * klass)
207 {
208   GObjectClass *gobject_class;
209   GstElementClass *gstelement_class;
210   GstBaseSrcClass *gstbasesrc_class;
211   GstPushSrcClass *gstpushsrc_class;
212
213   gobject_class = (GObjectClass *) klass;
214   gstelement_class = (GstElementClass *) klass;
215   gstbasesrc_class = (GstBaseSrcClass *) klass;
216   gstpushsrc_class = (GstPushSrcClass *) klass;
217
218   gobject_class->set_property = gst_soup_http_src_set_property;
219   gobject_class->get_property = gst_soup_http_src_get_property;
220   gobject_class->finalize = gst_soup_http_src_finalize;
221   gobject_class->dispose = gst_soup_http_src_dispose;
222
223   g_object_class_install_property (gobject_class,
224       PROP_LOCATION,
225       g_param_spec_string ("location", "Location",
226           "Location to read from", "",
227           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
228   g_object_class_install_property (gobject_class,
229       PROP_USER_AGENT,
230       g_param_spec_string ("user-agent", "User-Agent",
231           "Value of the User-Agent HTTP request header field",
232           DEFAULT_USER_AGENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
233   g_object_class_install_property (gobject_class,
234       PROP_AUTOMATIC_REDIRECT,
235       g_param_spec_boolean ("automatic-redirect", "automatic-redirect",
236           "Automatically follow HTTP redirects (HTTP Status Code 3xx)",
237           TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
238   g_object_class_install_property (gobject_class,
239       PROP_PROXY,
240       g_param_spec_string ("proxy", "Proxy",
241           "HTTP proxy server URI", "",
242           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
243   g_object_class_install_property (gobject_class,
244       PROP_USER_ID,
245       g_param_spec_string ("user-id", "user-id",
246           "HTTP location URI user id for authentication", "",
247           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
248   g_object_class_install_property (gobject_class, PROP_USER_PW,
249       g_param_spec_string ("user-pw", "user-pw",
250           "HTTP location URI user password for authentication", "",
251           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
252   g_object_class_install_property (gobject_class, PROP_PROXY_ID,
253       g_param_spec_string ("proxy-id", "proxy-id",
254           "HTTP proxy URI user id for authentication", "",
255           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
256   g_object_class_install_property (gobject_class, PROP_PROXY_PW,
257       g_param_spec_string ("proxy-pw", "proxy-pw",
258           "HTTP proxy URI user password for authentication", "",
259           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
260   g_object_class_install_property (gobject_class, PROP_COOKIES,
261       g_param_spec_boxed ("cookies", "Cookies", "HTTP request cookies",
262           G_TYPE_STRV, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
263   g_object_class_install_property (gobject_class, PROP_IS_LIVE,
264       g_param_spec_boolean ("is-live", "is-live", "Act like a live source",
265           FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
266   g_object_class_install_property (gobject_class, PROP_TIMEOUT,
267       g_param_spec_uint ("timeout", "timeout",
268           "Value in seconds to timeout a blocking I/O (0 = No timeout).", 0,
269           3600, DEFAULT_TIMEOUT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
270   g_object_class_install_property (gobject_class, PROP_EXTRA_HEADERS,
271       g_param_spec_boxed ("extra-headers", "Extra Headers",
272           "Extra headers to append to the HTTP request",
273           GST_TYPE_STRUCTURE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
274   g_object_class_install_property (gobject_class, PROP_IRADIO_MODE,
275       g_param_spec_boolean ("iradio-mode", "iradio-mode",
276           "Enable internet radio mode (ask server to send shoutcast/icecast "
277           "metadata interleaved with the actual stream data)",
278           DEFAULT_IRADIO_MODE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
279
280  /**
281    * GstSoupHTTPSrc::http-log-level:
282    *
283    * If set and > 0, captures and dumps HTTP session data as
284    * log messages if log level >= GST_LEVEL_TRACE
285    *
286    * Since: 1.4
287    */
288   g_object_class_install_property (gobject_class, PROP_SOUP_LOG_LEVEL,
289       g_param_spec_enum ("http-log-level", "HTTP log level",
290           "Set log level for soup's HTTP session log",
291           SOUP_TYPE_LOGGER_LOG_LEVEL, DEFAULT_SOUP_LOG_LEVEL,
292           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
293
294  /**
295    * GstSoupHTTPSrc::compress:
296    *
297    * If set to %TRUE, souphttpsrc will automatically handle gzip
298    * and deflate Content-Encodings. This does not make much difference
299    * and causes more load for normal media files, but makes a real
300    * difference in size for plaintext files.
301    *
302    * Since: 1.4
303    */
304   g_object_class_install_property (gobject_class, PROP_COMPRESS,
305       g_param_spec_boolean ("compress", "Compress",
306           "Allow compressed content encodings",
307           DEFAULT_COMPRESS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
308
309  /**
310    * GstSoupHTTPSrc::keep-alive:
311    *
312    * If set to %TRUE, souphttpsrc will keep alive connections when being
313    * set to READY state and only will close connections when connecting
314    * to a different server or when going to NULL state..
315    *
316    * Since: 1.4
317    */
318   g_object_class_install_property (gobject_class, PROP_KEEP_ALIVE,
319       g_param_spec_boolean ("keep-alive", "keep-alive",
320           "Use HTTP persistent connections", DEFAULT_KEEP_ALIVE,
321           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
322
323  /**
324    * GstSoupHTTPSrc::ssl-strict:
325    *
326    * If set to %TRUE, souphttpsrc will reject all SSL certificates that
327    * are considered invalid.
328    *
329    * Since: 1.4
330    */
331   g_object_class_install_property (gobject_class, PROP_SSL_STRICT,
332       g_param_spec_boolean ("ssl-strict", "SSL Strict",
333           "Strict SSL certificate checking", DEFAULT_SSL_STRICT,
334           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
335
336  /**
337    * GstSoupHTTPSrc::ssl-ca-file:
338    *
339    * A SSL anchor CA file that should be used for checking certificates
340    * instead of the system CA file.
341    *
342    * If this property is non-%NULL, #GstSoupHTTPSrc::ssl-use-system-ca-file
343    * value will be ignored.
344    *
345    * Deprecated: Use #GstSoupHTTPSrc::tls-database property instead.
346    * Since: 1.4
347    */
348   g_object_class_install_property (gobject_class, PROP_SSL_CA_FILE,
349       g_param_spec_string ("ssl-ca-file", "SSL CA File",
350           "Location of a SSL anchor CA file to use", DEFAULT_SSL_CA_FILE,
351           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
352
353  /**
354    * GstSoupHTTPSrc::ssl-use-system-ca-file:
355    *
356    * If set to %TRUE, souphttpsrc will use the system's CA file for
357    * checking certificates, unless #GstSoupHTTPSrc::ssl-ca-file or
358    * #GstSoupHTTPSrc::tls-database are non-%NULL.
359    *
360    * Since: 1.4
361    */
362   g_object_class_install_property (gobject_class, PROP_SSL_USE_SYSTEM_CA_FILE,
363       g_param_spec_boolean ("ssl-use-system-ca-file", "Use System CA File",
364           "Use system CA file", DEFAULT_SSL_USE_SYSTEM_CA_FILE,
365           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
366
367   /**
368    * GstSoupHTTPSrc::tls-database:
369    *
370    * TLS database with anchor certificate authorities used to validate
371    * the server certificate.
372    *
373    * If this property is non-%NULL, #GstSoupHTTPSrc::ssl-use-system-ca-file
374    * and #GstSoupHTTPSrc::ssl-ca-file values will be ignored.
375    *
376    * Since: 1.6
377    */
378   g_object_class_install_property (gobject_class, PROP_TLS_DATABASE,
379       g_param_spec_object ("tls-database", "TLS database",
380           "TLS database with anchor certificate authorities used to validate the server certificate",
381           G_TYPE_TLS_DATABASE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
382
383  /**
384    * GstSoupHTTPSrc::retries:
385    *
386    * Maximum number of retries until giving up.
387    *
388    * Since: 1.4
389    */
390   g_object_class_install_property (gobject_class, PROP_RETRIES,
391       g_param_spec_int ("retries", "Retries",
392           "Maximum number of retries until giving up (-1=infinite)", -1,
393           G_MAXINT, DEFAULT_RETRIES,
394           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
395
396  /**
397    * GstSoupHTTPSrc::method
398    *
399    * The HTTP method to use when making a request
400    *
401    * Since: 1.6
402    */
403   g_object_class_install_property (gobject_class, PROP_METHOD,
404       g_param_spec_string ("method", "HTTP method",
405           "The HTTP method to use (GET, HEAD, OPTIONS, etc)",
406           DEFAULT_SOUP_METHOD, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
407
408   gst_element_class_add_pad_template (gstelement_class,
409       gst_static_pad_template_get (&srctemplate));
410
411   gst_element_class_set_static_metadata (gstelement_class, "HTTP client source",
412       "Source/Network",
413       "Receive data as a client over the network via HTTP using SOUP",
414       "Wouter Cloetens <wouter@mind.be>");
415   gstelement_class->change_state =
416       GST_DEBUG_FUNCPTR (gst_soup_http_src_change_state);
417
418   gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_soup_http_src_start);
419   gstbasesrc_class->stop = GST_DEBUG_FUNCPTR (gst_soup_http_src_stop);
420   gstbasesrc_class->unlock = GST_DEBUG_FUNCPTR (gst_soup_http_src_unlock);
421   gstbasesrc_class->unlock_stop =
422       GST_DEBUG_FUNCPTR (gst_soup_http_src_unlock_stop);
423   gstbasesrc_class->get_size = GST_DEBUG_FUNCPTR (gst_soup_http_src_get_size);
424   gstbasesrc_class->is_seekable =
425       GST_DEBUG_FUNCPTR (gst_soup_http_src_is_seekable);
426   gstbasesrc_class->do_seek = GST_DEBUG_FUNCPTR (gst_soup_http_src_do_seek);
427   gstbasesrc_class->query = GST_DEBUG_FUNCPTR (gst_soup_http_src_query);
428
429   gstpushsrc_class->create = GST_DEBUG_FUNCPTR (gst_soup_http_src_create);
430
431   GST_DEBUG_CATEGORY_INIT (souphttpsrc_debug, "souphttpsrc", 0,
432       "SOUP HTTP src");
433 }
434
435 static void
436 gst_soup_http_src_reset (GstSoupHTTPSrc * src)
437 {
438   src->interrupted = FALSE;
439   src->retry = FALSE;
440   src->retry_count = 0;
441   src->have_size = FALSE;
442   src->got_headers = FALSE;
443   src->seekable = FALSE;
444   src->read_position = 0;
445   src->request_position = 0;
446   src->stop_position = -1;
447   src->content_size = 0;
448   src->have_body = FALSE;
449
450   src->ret = GST_FLOW_OK;
451
452   gst_caps_replace (&src->src_caps, NULL);
453   g_free (src->iradio_name);
454   src->iradio_name = NULL;
455   g_free (src->iradio_genre);
456   src->iradio_genre = NULL;
457   g_free (src->iradio_url);
458   src->iradio_url = NULL;
459 }
460
461 static void
462 gst_soup_http_src_init (GstSoupHTTPSrc * src)
463 {
464   const gchar *proxy;
465
466   g_mutex_init (&src->mutex);
467   g_cond_init (&src->request_finished_cond);
468   src->location = NULL;
469   src->redirection_uri = NULL;
470   src->automatic_redirect = TRUE;
471   src->user_agent = g_strdup (DEFAULT_USER_AGENT);
472   src->user_id = NULL;
473   src->user_pw = NULL;
474   src->proxy_id = NULL;
475   src->proxy_pw = NULL;
476   src->cookies = NULL;
477   src->iradio_mode = DEFAULT_IRADIO_MODE;
478   src->loop = NULL;
479   src->context = NULL;
480   src->session = NULL;
481   src->msg = NULL;
482   src->timeout = DEFAULT_TIMEOUT;
483   src->log_level = DEFAULT_SOUP_LOG_LEVEL;
484   src->ssl_strict = DEFAULT_SSL_STRICT;
485   src->ssl_use_system_ca_file = DEFAULT_SSL_USE_SYSTEM_CA_FILE;
486   src->tls_database = DEFAULT_TLS_DATABASE;
487   src->max_retries = DEFAULT_RETRIES;
488   src->method = DEFAULT_SOUP_METHOD;
489   proxy = g_getenv ("http_proxy");
490   if (!gst_soup_http_src_set_proxy (src, proxy)) {
491     GST_WARNING_OBJECT (src,
492         "The proxy in the http_proxy env var (\"%s\") cannot be parsed.",
493         proxy);
494   }
495 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
496   src->cookie_jar  = NULL;
497 #endif
498   gst_base_src_set_automatic_eos (GST_BASE_SRC (src), FALSE);
499
500   gst_soup_http_src_reset (src);
501 }
502
503 static void
504 gst_soup_http_src_dispose (GObject * gobject)
505 {
506   GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (gobject);
507
508   GST_DEBUG_OBJECT (src, "dispose");
509
510   gst_soup_http_src_session_close (src);
511
512   G_OBJECT_CLASS (parent_class)->dispose (gobject);
513 }
514
515 static void
516 gst_soup_http_src_finalize (GObject * gobject)
517 {
518   GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (gobject);
519
520   GST_DEBUG_OBJECT (src, "finalize");
521
522   g_mutex_clear (&src->mutex);
523   g_cond_clear (&src->request_finished_cond);
524   g_free (src->location);
525   if (src->redirection_uri) {
526     g_free (src->redirection_uri);
527   }
528   g_free (src->user_agent);
529   if (src->proxy != NULL) {
530     soup_uri_free (src->proxy);
531   }
532   g_free (src->user_id);
533   g_free (src->user_pw);
534   g_free (src->proxy_id);
535   g_free (src->proxy_pw);
536   g_strfreev (src->cookies);
537
538   if (src->extra_headers) {
539     gst_structure_free (src->extra_headers);
540     src->extra_headers = NULL;
541   }
542
543   g_free (src->ssl_ca_file);
544
545   if (src->tls_database)
546     g_object_unref (src->tls_database);
547   g_free (src->method);
548
549   G_OBJECT_CLASS (parent_class)->finalize (gobject);
550 }
551
552 static void
553 gst_soup_http_src_set_property (GObject * object, guint prop_id,
554     const GValue * value, GParamSpec * pspec)
555 {
556   GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (object);
557
558   switch (prop_id) {
559     case PROP_LOCATION:
560     {
561       const gchar *location;
562
563       location = g_value_get_string (value);
564
565       if (location == NULL) {
566         GST_WARNING ("location property cannot be NULL");
567         goto done;
568       }
569       if (!gst_soup_http_src_set_location (src, location, NULL)) {
570         GST_WARNING ("badly formatted location");
571         goto done;
572       }
573       break;
574     }
575     case PROP_USER_AGENT:
576       if (src->user_agent)
577         g_free (src->user_agent);
578       src->user_agent = g_value_dup_string (value);
579       break;
580     case PROP_IRADIO_MODE:
581       src->iradio_mode = g_value_get_boolean (value);
582       break;
583     case PROP_AUTOMATIC_REDIRECT:
584       src->automatic_redirect = g_value_get_boolean (value);
585       break;
586     case PROP_PROXY:
587     {
588       const gchar *proxy;
589
590       proxy = g_value_get_string (value);
591       if (!gst_soup_http_src_set_proxy (src, proxy)) {
592         GST_WARNING ("badly formatted proxy URI");
593         goto done;
594       }
595       break;
596     }
597     case PROP_COOKIES:
598 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
599     {
600       char **array;
601       SoupURI *base_uri;
602       g_strfreev (src->cookies);
603       src->cookies = g_strdupv (g_value_get_boxed (value));
604
605       if (src->cookie_jar && ((array = src->cookies) != NULL)) {
606         base_uri = soup_uri_new (src->location);
607         GST_INFO_OBJECT (src, "request to set cookies...");
608         while (*array != NULL) {
609           soup_cookie_jar_add_cookie (src->cookie_jar,
610               soup_cookie_parse (*array++, base_uri));
611         }
612         soup_uri_free (base_uri);
613       } else {
614         GST_INFO_OBJECT (src, "set cookies after session creation");
615       }
616     }
617 #else
618       g_strfreev (src->cookies);
619       src->cookies = g_strdupv (g_value_get_boxed (value));
620 #endif
621       break;
622     case PROP_IS_LIVE:
623       gst_base_src_set_live (GST_BASE_SRC (src), g_value_get_boolean (value));
624       break;
625     case PROP_USER_ID:
626       if (src->user_id)
627         g_free (src->user_id);
628       src->user_id = g_value_dup_string (value);
629       break;
630     case PROP_USER_PW:
631       if (src->user_pw)
632         g_free (src->user_pw);
633       src->user_pw = g_value_dup_string (value);
634       break;
635     case PROP_PROXY_ID:
636       if (src->proxy_id)
637         g_free (src->proxy_id);
638       src->proxy_id = g_value_dup_string (value);
639       break;
640     case PROP_PROXY_PW:
641       if (src->proxy_pw)
642         g_free (src->proxy_pw);
643       src->proxy_pw = g_value_dup_string (value);
644       break;
645     case PROP_TIMEOUT:
646       src->timeout = g_value_get_uint (value);
647       break;
648     case PROP_EXTRA_HEADERS:{
649       const GstStructure *s = gst_value_get_structure (value);
650
651       if (src->extra_headers)
652         gst_structure_free (src->extra_headers);
653
654       src->extra_headers = s ? gst_structure_copy (s) : NULL;
655       break;
656     }
657     case PROP_SOUP_LOG_LEVEL:
658       src->log_level = g_value_get_enum (value);
659       break;
660     case PROP_COMPRESS:
661       src->compress = g_value_get_boolean (value);
662       break;
663     case PROP_KEEP_ALIVE:
664       src->keep_alive = g_value_get_boolean (value);
665       break;
666     case PROP_SSL_STRICT:
667       src->ssl_strict = g_value_get_boolean (value);
668       break;
669     case PROP_SSL_CA_FILE:
670       if (src->ssl_ca_file)
671         g_free (src->ssl_ca_file);
672       src->ssl_ca_file = g_value_dup_string (value);
673       break;
674     case PROP_SSL_USE_SYSTEM_CA_FILE:
675       src->ssl_use_system_ca_file = g_value_get_boolean (value);
676       break;
677     case PROP_TLS_DATABASE:
678       g_clear_object (&src->tls_database);
679       src->tls_database = g_value_dup_object (value);
680       break;
681     case PROP_RETRIES:
682       src->max_retries = g_value_get_int (value);
683       break;
684     case PROP_METHOD:
685       g_free (src->method);
686       src->method = g_value_dup_string (value);
687       break;
688     default:
689       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
690       break;
691   }
692 done:
693   return;
694 }
695
696 static void
697 gst_soup_http_src_get_property (GObject * object, guint prop_id,
698     GValue * value, GParamSpec * pspec)
699 {
700   GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (object);
701
702   switch (prop_id) {
703     case PROP_LOCATION:
704       g_value_set_string (value, src->location);
705       break;
706     case PROP_USER_AGENT:
707       g_value_set_string (value, src->user_agent);
708       break;
709     case PROP_AUTOMATIC_REDIRECT:
710       g_value_set_boolean (value, src->automatic_redirect);
711       break;
712     case PROP_PROXY:
713       if (src->proxy == NULL)
714         g_value_set_static_string (value, "");
715       else {
716         char *proxy = soup_uri_to_string (src->proxy, FALSE);
717
718         g_value_set_string (value, proxy);
719         g_free (proxy);
720       }
721       break;
722     case PROP_COOKIES:
723 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
724     {
725         GSList *cookie_list, *c;
726         gchar **cookies, **array;
727
728         cookies = NULL;
729         if ((src->cookie_jar) &&
730             ((cookie_list = soup_cookie_jar_all_cookies (src->cookie_jar)) != NULL)) {
731           cookies = g_new0 (gchar *, g_slist_length(cookie_list) + 1);
732           array = cookies;
733           for (c = cookie_list; c; c = c->next) {
734             *array++ = soup_cookie_to_set_cookie_header ((SoupCookie *)(c->data));
735           }
736           soup_cookies_free (cookie_list);
737         }
738         g_value_set_boxed (value, cookies);
739     }
740 #else
741         g_value_set_boxed (value, g_strdupv (src->cookies));
742 #endif
743       break;
744     case PROP_IS_LIVE:
745       g_value_set_boolean (value, gst_base_src_is_live (GST_BASE_SRC (src)));
746       break;
747     case PROP_IRADIO_MODE:
748       g_value_set_boolean (value, src->iradio_mode);
749       break;
750     case PROP_USER_ID:
751       g_value_set_string (value, src->user_id);
752       break;
753     case PROP_USER_PW:
754       g_value_set_string (value, src->user_pw);
755       break;
756     case PROP_PROXY_ID:
757       g_value_set_string (value, src->proxy_id);
758       break;
759     case PROP_PROXY_PW:
760       g_value_set_string (value, src->proxy_pw);
761       break;
762     case PROP_TIMEOUT:
763       g_value_set_uint (value, src->timeout);
764       break;
765     case PROP_EXTRA_HEADERS:
766       gst_value_set_structure (value, src->extra_headers);
767       break;
768     case PROP_SOUP_LOG_LEVEL:
769       g_value_set_enum (value, src->log_level);
770       break;
771     case PROP_COMPRESS:
772       g_value_set_boolean (value, src->compress);
773       break;
774     case PROP_KEEP_ALIVE:
775       g_value_set_boolean (value, src->keep_alive);
776       break;
777     case PROP_SSL_STRICT:
778       g_value_set_boolean (value, src->ssl_strict);
779       break;
780     case PROP_SSL_CA_FILE:
781       g_value_set_string (value, src->ssl_ca_file);
782       break;
783     case PROP_SSL_USE_SYSTEM_CA_FILE:
784       g_value_set_boolean (value, src->ssl_use_system_ca_file);
785       break;
786     case PROP_TLS_DATABASE:
787       g_value_set_object (value, src->tls_database);
788       break;
789     case PROP_RETRIES:
790       g_value_set_int (value, src->max_retries);
791       break;
792     case PROP_METHOD:
793       g_value_set_string (value, src->method);
794       break;
795     default:
796       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
797       break;
798   }
799 }
800
801 static gchar *
802 gst_soup_http_src_unicodify (const gchar * str)
803 {
804   const gchar *env_vars[] = { "GST_ICY_TAG_ENCODING",
805     "GST_TAG_ENCODING", NULL
806   };
807
808   return gst_tag_freeform_string_to_utf8 (str, -1, env_vars);
809 }
810
811 static void
812 gst_soup_http_src_cancel_message (GstSoupHTTPSrc * src)
813 {
814   if (src->msg != NULL) {
815     GST_INFO_OBJECT (src, "Cancelling message");
816     src->session_io_status = GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_CANCELLED;
817     soup_session_cancel_message (src->session, src->msg, SOUP_STATUS_CANCELLED);
818   }
819   src->session_io_status = GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_IDLE;
820   src->msg = NULL;
821 }
822
823 static void
824 gst_soup_http_src_queue_message (GstSoupHTTPSrc * src)
825 {
826   soup_session_queue_message (src->session, src->msg,
827       (SoupSessionCallback) gst_soup_http_src_response_cb, src);
828   src->session_io_status = GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_QUEUED;
829 }
830
831 static gboolean
832 gst_soup_http_src_add_range_header (GstSoupHTTPSrc * src, guint64 offset,
833     guint64 stop_offset)
834 {
835   gchar buf[64];
836
837   gint rc;
838
839   soup_message_headers_remove (src->msg->request_headers, "Range");
840 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
841 /*[prasenjit.c]This changes are needed to enable Seekable Contents from server.
842 We have observed that , for few specific networks ( VODAFONE ) , without theabove headers ,
843 Youtube is sending non-seekable contents to the Client.
844 */
845   if (offset >=0 || stop_offset != -1) {
846 #else
847   if (offset || stop_offset != -1) {
848 #endif
849     if (stop_offset != -1) {
850       rc = g_snprintf (buf, sizeof (buf), "bytes=%" G_GUINT64_FORMAT "-%"
851           G_GUINT64_FORMAT, offset, stop_offset);
852     } else {
853       rc = g_snprintf (buf, sizeof (buf), "bytes=%" G_GUINT64_FORMAT "-",
854           offset);
855     }
856     if (rc > sizeof (buf) || rc < 0)
857       return FALSE;
858     soup_message_headers_append (src->msg->request_headers, "Range", buf);
859   }
860   src->read_position = offset;
861   return TRUE;
862 }
863
864 static gboolean
865 _append_extra_header (GQuark field_id, const GValue * value, gpointer user_data)
866 {
867   GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (user_data);
868   const gchar *field_name = g_quark_to_string (field_id);
869   gchar *field_content = NULL;
870
871   if (G_VALUE_TYPE (value) == G_TYPE_STRING) {
872     field_content = g_value_dup_string (value);
873   } else {
874     GValue dest = { 0, };
875
876     g_value_init (&dest, G_TYPE_STRING);
877     if (g_value_transform (value, &dest)) {
878       field_content = g_value_dup_string (&dest);
879     }
880   }
881
882   if (field_content == NULL) {
883     GST_ERROR_OBJECT (src, "extra-headers field '%s' contains no value "
884         "or can't be converted to a string", field_name);
885     return FALSE;
886   }
887
888   GST_DEBUG_OBJECT (src, "Appending extra header: \"%s: %s\"", field_name,
889       field_content);
890   soup_message_headers_append (src->msg->request_headers, field_name,
891       field_content);
892
893 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
894   if (!g_ascii_strcasecmp(field_name, "Cookie")) {
895     SoupURI *uri = NULL;
896     SoupCookie *cookie_parsed = NULL;
897
898     if (strlen(field_content) > 0) {
899       gchar *tmp_field = NULL;
900
901       uri = soup_uri_new (src->location);
902
903       tmp_field = strtok (field_content, ";");
904
905       while (tmp_field != NULL) {
906         GST_DEBUG_OBJECT (src, "field_content = %s", tmp_field);
907
908         cookie_parsed = soup_cookie_parse(tmp_field, uri);
909         GST_DEBUG_OBJECT (src, "cookie parsed = %p", cookie_parsed);
910
911         if (src->cookie_jar)
912           soup_cookie_jar_add_cookie (src->cookie_jar, cookie_parsed);
913
914         tmp_field = strtok (NULL, ";");
915       }
916       soup_uri_free (uri);
917     }
918   }
919 #endif
920
921   g_free (field_content);
922
923   return TRUE;
924 }
925
926 static gboolean
927 _append_extra_headers (GQuark field_id, const GValue * value,
928     gpointer user_data)
929 {
930   if (G_VALUE_TYPE (value) == GST_TYPE_ARRAY) {
931     guint n = gst_value_array_get_size (value);
932     guint i;
933
934     for (i = 0; i < n; i++) {
935       const GValue *v = gst_value_array_get_value (value, i);
936
937       if (!_append_extra_header (field_id, v, user_data))
938         return FALSE;
939     }
940   } else if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
941     guint n = gst_value_list_get_size (value);
942     guint i;
943
944     for (i = 0; i < n; i++) {
945       const GValue *v = gst_value_list_get_value (value, i);
946
947       if (!_append_extra_header (field_id, v, user_data))
948         return FALSE;
949     }
950   } else {
951     return _append_extra_header (field_id, value, user_data);
952   }
953
954   return TRUE;
955 }
956
957
958 static gboolean
959 gst_soup_http_src_add_extra_headers (GstSoupHTTPSrc * src)
960 {
961   if (!src->extra_headers)
962     return TRUE;
963
964   return gst_structure_foreach (src->extra_headers, _append_extra_headers, src);
965 }
966
967
968 static void
969 gst_soup_http_src_session_unpause_message (GstSoupHTTPSrc * src)
970 {
971   soup_session_unpause_message (src->session, src->msg);
972 }
973
974 static void
975 gst_soup_http_src_session_pause_message (GstSoupHTTPSrc * src)
976 {
977   soup_session_pause_message (src->session, src->msg);
978 }
979
980 static gboolean
981 gst_soup_http_src_session_open (GstSoupHTTPSrc * src)
982 {
983   if (src->session) {
984     GST_DEBUG_OBJECT (src, "Session is already open");
985     return TRUE;
986   }
987
988   if (!src->location) {
989     GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (_("No URL set.")),
990         ("Missing location property"));
991     return FALSE;
992   }
993
994   if (!src->context)
995     src->context = g_main_context_new ();
996
997   if (!src->loop)
998     src->loop = g_main_loop_new (src->context, TRUE);
999   if (!src->loop) {
1000     GST_ELEMENT_ERROR (src, LIBRARY, INIT,
1001         (NULL), ("Failed to start GMainLoop"));
1002     g_main_context_unref (src->context);
1003     return FALSE;
1004   }
1005
1006   if (!src->session) {
1007     GST_DEBUG_OBJECT (src, "Creating session");
1008     if (src->proxy == NULL) {
1009       src->session =
1010           soup_session_async_new_with_options (SOUP_SESSION_ASYNC_CONTEXT,
1011           src->context, SOUP_SESSION_USER_AGENT, src->user_agent,
1012           SOUP_SESSION_TIMEOUT, src->timeout,
1013           SOUP_SESSION_SSL_STRICT, src->ssl_strict,
1014           SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_PROXY_RESOLVER_DEFAULT,
1015           NULL);
1016     } else {
1017       src->session =
1018           soup_session_async_new_with_options (SOUP_SESSION_ASYNC_CONTEXT,
1019           src->context, SOUP_SESSION_PROXY_URI, src->proxy,
1020           SOUP_SESSION_TIMEOUT, src->timeout,
1021           SOUP_SESSION_SSL_STRICT, src->ssl_strict,
1022           SOUP_SESSION_USER_AGENT, src->user_agent, NULL);
1023     }
1024
1025     if (!src->session) {
1026       GST_ELEMENT_ERROR (src, LIBRARY, INIT,
1027           (NULL), ("Failed to create async session"));
1028       return FALSE;
1029     }
1030
1031 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
1032     {
1033       char **array = NULL;
1034       SoupURI *base_uri;
1035       SoupCookie *soup_cookie = NULL;
1036
1037       soup_session_add_feature_by_type (src->session, SOUP_TYPE_COOKIE_JAR);
1038       src->cookie_jar = SOUP_COOKIE_JAR (soup_session_get_feature (src->session, SOUP_TYPE_COOKIE_JAR));
1039       if ((array = src->cookies) != NULL) {
1040         base_uri = soup_uri_new (src->location);
1041         while (*array != NULL) {
1042           soup_cookie = soup_cookie_parse (*array++, base_uri);
1043           if (soup_cookie != NULL) {
1044             GST_INFO_OBJECT (src, "adding cookies..");
1045             soup_cookie_jar_add_cookie (src->cookie_jar, soup_cookie);
1046           }
1047         }
1048         soup_uri_free (base_uri);
1049       }
1050     }
1051 #endif
1052
1053     g_signal_connect (src->session, "authenticate",
1054         G_CALLBACK (gst_soup_http_src_authenticate_cb), src);
1055
1056     /* Set up logging */
1057     gst_soup_util_log_setup (src->session, src->log_level, GST_ELEMENT (src));
1058     if (src->tls_database)
1059       g_object_set (src->session, "tls-database", src->tls_database, NULL);
1060     else if (src->ssl_ca_file)
1061       g_object_set (src->session, "ssl-ca-file", src->ssl_ca_file, NULL);
1062     else
1063       g_object_set (src->session, "ssl-use-system-ca-file",
1064           src->ssl_use_system_ca_file, NULL);
1065   } else {
1066     GST_DEBUG_OBJECT (src, "Re-using session");
1067   }
1068
1069   if (src->compress)
1070     soup_session_add_feature_by_type (src->session, SOUP_TYPE_CONTENT_DECODER);
1071   else
1072     soup_session_remove_feature_by_type (src->session,
1073         SOUP_TYPE_CONTENT_DECODER);
1074
1075   return TRUE;
1076 }
1077
1078 #ifdef LIBSOUP_DOES_NOT_STEAL_OUR_CONTEXT
1079 static gboolean
1080 dummy_idle_cb (gpointer data)
1081 {
1082   return FALSE /* Idle source is removed */ ;
1083 }
1084 #endif
1085
1086 static void
1087 gst_soup_http_src_session_close (GstSoupHTTPSrc * src)
1088 {
1089   GST_DEBUG_OBJECT (src, "Closing session");
1090
1091   if (src->loop)
1092     g_main_loop_quit (src->loop);
1093
1094   g_mutex_lock (&src->mutex);
1095   if (src->session) {
1096 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
1097 //[prasenjit.c] When Playback is ongoing and Browser is moved to background ( Pressing Menu or Home Key ), The Session gets destroyed.
1098 // But the cookie_jar property remains unfreed. This results in garbage pointer and causes crash.
1099 // Removing the cookie_jar feature during close session of browser to handle the issue.
1100     GST_DEBUG_OBJECT (src, "Removing Cookie Jar instance");
1101     soup_session_remove_feature_by_type(src->session, SOUP_TYPE_COOKIE_JAR);
1102     src->cookie_jar = NULL;
1103 #endif
1104     soup_session_abort (src->session);  /* This unrefs the message. */
1105     g_object_unref (src->session);
1106     src->session = NULL;
1107     src->msg = NULL;
1108   }
1109   if (src->loop) {
1110 #ifdef LIBSOUP_DOES_NOT_STEAL_OUR_CONTEXT
1111     GSource *idle_source;
1112
1113     /* Iterating the main context to give GIO cancellables a chance
1114      * to initiate cleanups. Wihout this, resources allocated by
1115      * libsoup for the connection are not released and socket fd is
1116      * leaked. */
1117     idle_source = g_idle_source_new ();
1118     /* Suppressing "idle souce without callback" warning */
1119     g_source_set_callback (idle_source, dummy_idle_cb, NULL, NULL);
1120     g_source_set_priority (idle_source, G_PRIORITY_LOW);
1121     g_source_attach (idle_source, src->context);
1122     /* Acquiring the context. Idle source guarantees that we'll not block. */
1123     g_main_context_push_thread_default (src->context);
1124     g_main_context_iteration (src->context, TRUE);
1125     /* Ensuring that there's no unhandled pending events left. */
1126     while (g_main_context_iteration (src->context, FALSE));
1127     g_main_context_pop_thread_default (src->context);
1128     g_source_unref (idle_source);
1129 #endif
1130
1131     g_main_loop_unref (src->loop);
1132     g_main_context_unref (src->context);
1133     src->loop = NULL;
1134     src->context = NULL;
1135   }
1136   g_mutex_unlock (&src->mutex);
1137 }
1138
1139 static void
1140 gst_soup_http_src_authenticate_cb (SoupSession * session, SoupMessage * msg,
1141     SoupAuth * auth, gboolean retrying, GstSoupHTTPSrc * src)
1142 {
1143   if (!retrying) {
1144     /* First time authentication only, if we fail and are called again with retry true fall through */
1145     if (msg->status_code == SOUP_STATUS_UNAUTHORIZED) {
1146       if (src->user_id && src->user_pw)
1147         soup_auth_authenticate (auth, src->user_id, src->user_pw);
1148     } else if (msg->status_code == SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
1149       if (src->proxy_id && src->proxy_pw)
1150         soup_auth_authenticate (auth, src->proxy_id, src->proxy_pw);
1151     }
1152   }
1153 }
1154
1155 static void
1156 insert_http_header (const gchar * name, const gchar * value, gpointer user_data)
1157 {
1158   GstStructure *headers = user_data;
1159   const GValue *gv;
1160
1161   gv = gst_structure_get_value (headers, name);
1162   if (gv && GST_VALUE_HOLDS_ARRAY (gv)) {
1163     GValue v = G_VALUE_INIT;
1164
1165     g_value_init (&v, G_TYPE_STRING);
1166     g_value_set_string (&v, value);
1167     gst_value_array_append_value ((GValue *) gv, &v);
1168     g_value_unset (&v);
1169   } else if (gv && G_VALUE_HOLDS_STRING (gv)) {
1170     GValue arr = G_VALUE_INIT;
1171     GValue v = G_VALUE_INIT;
1172     const gchar *old_value = g_value_get_string (gv);
1173
1174     g_value_init (&arr, GST_TYPE_ARRAY);
1175     g_value_init (&v, G_TYPE_STRING);
1176     g_value_set_string (&v, old_value);
1177     gst_value_array_append_value (&arr, &v);
1178     g_value_set_string (&v, value);
1179     gst_value_array_append_value (&arr, &v);
1180
1181     gst_structure_set_value (headers, name, &arr);
1182     g_value_unset (&v);
1183     g_value_unset (&arr);
1184   } else {
1185     gst_structure_set (headers, name, G_TYPE_STRING, value, NULL);
1186   }
1187 }
1188
1189 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
1190 static void
1191 gst_soup_http_src_headers_foreach (const gchar * name, const gchar * val,
1192     gpointer src)
1193 {
1194   GST_INFO_OBJECT (src, " %s: %s", name, val);
1195
1196   if (g_ascii_strcasecmp (name, "Set-Cookie") == 0)
1197   {
1198     if (val)
1199     {
1200       gboolean bret = FALSE;
1201       GstStructure *s = NULL;
1202       GstSoupHTTPSrc * tmp = src;
1203       SoupURI *uri;
1204
1205       uri =  soup_uri_new (tmp->location);
1206
1207       /* post current bandwith & uri to application */
1208       s = gst_structure_new ("cookies",
1209             "updated-cookie", G_TYPE_STRING, val,
1210             "updated-url", G_TYPE_STRING, tmp->location, NULL);
1211       bret = gst_element_post_message (GST_ELEMENT_CAST (src), gst_message_new_element (GST_OBJECT_CAST (src), s));
1212       soup_cookie_jar_set_cookie (tmp->cookie_jar,  uri, val);
1213       soup_uri_free (uri);
1214
1215       GST_INFO_OBJECT (src, "request url [%s], posted cookies [%s] msg and returned = %d", tmp->location, val, bret);
1216     }
1217   }
1218 }
1219 #endif
1220
1221 static void
1222 gst_soup_http_src_got_headers_cb (SoupMessage * msg, GstSoupHTTPSrc * src)
1223 {
1224   const char *value;
1225   GstTagList *tag_list;
1226   GstBaseSrc *basesrc;
1227   guint64 newsize;
1228   GHashTable *params = NULL;
1229   GstEvent *http_headers_event;
1230   GstStructure *http_headers, *headers;
1231   const gchar *accept_ranges;
1232
1233   GST_INFO_OBJECT (src, "got headers");
1234 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
1235   soup_message_headers_foreach (msg->response_headers,
1236       gst_soup_http_src_headers_foreach, src);
1237 #endif
1238   if (msg->status_code == SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED &&
1239       src->proxy_id && src->proxy_pw)
1240     return;
1241
1242   if (src->automatic_redirect && SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
1243     src->redirection_uri = g_strdup (soup_message_headers_get_one
1244         (msg->response_headers, "Location"));
1245     src->redirection_permanent =
1246         (msg->status_code == SOUP_STATUS_MOVED_PERMANENTLY);
1247     GST_DEBUG_OBJECT (src, "%u redirect to \"%s\" (permanent %d)",
1248         msg->status_code, src->redirection_uri, src->redirection_permanent);
1249     return;
1250   }
1251
1252   if (msg->status_code == SOUP_STATUS_UNAUTHORIZED)
1253     return;
1254
1255   src->session_io_status = GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING;
1256   src->got_headers = TRUE;
1257
1258   http_headers = gst_structure_new_empty ("http-headers");
1259   gst_structure_set (http_headers, "uri", G_TYPE_STRING, src->location, NULL);
1260   if (src->redirection_uri)
1261     gst_structure_set (http_headers, "redirection-uri", G_TYPE_STRING,
1262         src->redirection_uri, NULL);
1263   headers = gst_structure_new_empty ("request-headers");
1264   soup_message_headers_foreach (msg->request_headers, insert_http_header,
1265       headers);
1266   gst_structure_set (http_headers, "request-headers", GST_TYPE_STRUCTURE,
1267       headers, NULL);
1268   gst_structure_free (headers);
1269   headers = gst_structure_new_empty ("response-headers");
1270   soup_message_headers_foreach (msg->response_headers, insert_http_header,
1271       headers);
1272   gst_structure_set (http_headers, "response-headers", GST_TYPE_STRUCTURE,
1273       headers, NULL);
1274   gst_structure_free (headers);
1275
1276   http_headers_event =
1277       gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_STICKY, http_headers);
1278   gst_event_replace (&src->http_headers_event, http_headers_event);
1279   gst_event_unref (http_headers_event);
1280
1281   /* Parse Content-Length. */
1282   if (soup_message_headers_get_encoding (msg->response_headers) ==
1283       SOUP_ENCODING_CONTENT_LENGTH) {
1284 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
1285       if (msg->status_code == SOUP_STATUS_PARTIAL_CONTENT) {
1286         newsize = src->request_position +
1287             soup_message_headers_get_content_length (msg->response_headers);
1288       } else {
1289         newsize = soup_message_headers_get_content_length (msg->response_headers);
1290       }
1291 #else
1292       newsize = src->request_position +
1293           soup_message_headers_get_content_length (msg->response_headers);
1294 #endif
1295     if (!src->have_size || (src->content_size != newsize)) {
1296       src->content_size = newsize;
1297       src->have_size = TRUE;
1298       src->seekable = TRUE;
1299       GST_DEBUG_OBJECT (src, "size = %" G_GUINT64_FORMAT, src->content_size);
1300
1301       basesrc = GST_BASE_SRC_CAST (src);
1302       basesrc->segment.duration = src->content_size;
1303       gst_element_post_message (GST_ELEMENT (src),
1304           gst_message_new_duration_changed (GST_OBJECT (src)));
1305     }
1306   }
1307
1308   /* If the server reports Accept-Ranges: none we don't have to try
1309    * doing range requests at all
1310    */
1311   if ((accept_ranges =
1312           soup_message_headers_get_one (msg->response_headers,
1313               "Accept-Ranges"))) {
1314     if (g_ascii_strcasecmp (accept_ranges, "none") == 0)
1315       src->seekable = FALSE;
1316   }
1317
1318   /* Icecast stuff */
1319   tag_list = gst_tag_list_new_empty ();
1320
1321   if ((value =
1322           soup_message_headers_get_one (msg->response_headers,
1323               "icy-metaint")) != NULL) {
1324     gint icy_metaint = atoi (value);
1325
1326     GST_DEBUG_OBJECT (src, "icy-metaint: %s (parsed: %d)", value, icy_metaint);
1327     if (icy_metaint > 0) {
1328       if (src->src_caps)
1329         gst_caps_unref (src->src_caps);
1330
1331       src->src_caps = gst_caps_new_simple ("application/x-icy",
1332           "metadata-interval", G_TYPE_INT, icy_metaint, NULL);
1333
1334       gst_base_src_set_caps (GST_BASE_SRC (src), src->src_caps);
1335     }
1336   }
1337   if ((value =
1338           soup_message_headers_get_content_type (msg->response_headers,
1339               &params)) != NULL) {
1340     GST_DEBUG_OBJECT (src, "Content-Type: %s", value);
1341     if (g_ascii_strcasecmp (value, "audio/L16") == 0) {
1342       gint channels = 2;
1343       gint rate = 44100;
1344       char *param;
1345
1346       if (src->src_caps)
1347         gst_caps_unref (src->src_caps);
1348
1349       param = g_hash_table_lookup (params, "channels");
1350       if (param != NULL)
1351         channels = atol (param);
1352
1353       param = g_hash_table_lookup (params, "rate");
1354       if (param != NULL)
1355         rate = atol (param);
1356
1357       src->src_caps = gst_caps_new_simple ("audio/x-raw",
1358           "format", G_TYPE_STRING, "S16BE",
1359           "layout", G_TYPE_STRING, "interleaved",
1360           "channels", G_TYPE_INT, channels, "rate", G_TYPE_INT, rate, NULL);
1361
1362       gst_base_src_set_caps (GST_BASE_SRC (src), src->src_caps);
1363     } else {
1364       /* Set the Content-Type field on the caps */
1365       if (src->src_caps) {
1366         src->src_caps = gst_caps_make_writable (src->src_caps);
1367         gst_caps_set_simple (src->src_caps, "content-type", G_TYPE_STRING,
1368             value, NULL);
1369         gst_base_src_set_caps (GST_BASE_SRC (src), src->src_caps);
1370       }
1371     }
1372   }
1373
1374   if (params != NULL)
1375     g_hash_table_destroy (params);
1376
1377   if ((value =
1378           soup_message_headers_get_one (msg->response_headers,
1379               "icy-name")) != NULL) {
1380     g_free (src->iradio_name);
1381     src->iradio_name = gst_soup_http_src_unicodify (value);
1382     if (src->iradio_name) {
1383       gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE, GST_TAG_ORGANIZATION,
1384           src->iradio_name, NULL);
1385     }
1386   }
1387   if ((value =
1388           soup_message_headers_get_one (msg->response_headers,
1389               "icy-genre")) != NULL) {
1390     g_free (src->iradio_genre);
1391     src->iradio_genre = gst_soup_http_src_unicodify (value);
1392     if (src->iradio_genre) {
1393       gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE, GST_TAG_GENRE,
1394           src->iradio_genre, NULL);
1395     }
1396   }
1397   if ((value = soup_message_headers_get_one (msg->response_headers, "icy-url"))
1398       != NULL) {
1399     g_free (src->iradio_url);
1400     src->iradio_url = gst_soup_http_src_unicodify (value);
1401     if (src->iradio_url) {
1402       gst_tag_list_add (tag_list, GST_TAG_MERGE_REPLACE, GST_TAG_LOCATION,
1403           src->iradio_url, NULL);
1404     }
1405   }
1406   if (!gst_tag_list_is_empty (tag_list)) {
1407     GST_DEBUG_OBJECT (src,
1408         "calling gst_element_found_tags with %" GST_PTR_FORMAT, tag_list);
1409     gst_pad_push_event (GST_BASE_SRC_PAD (src), gst_event_new_tag (tag_list));
1410   } else {
1411     gst_tag_list_unref (tag_list);
1412   }
1413
1414   /* Handle HTTP errors. */
1415   gst_soup_http_src_parse_status (msg, src);
1416
1417 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
1418   /* Check if Range header was respected. */
1419   if (src->ret == GST_FLOW_CUSTOM_ERROR &&
1420       src->read_position && msg->status_code != SOUP_STATUS_PARTIAL_CONTENT &&
1421       (src->request_position < src->content_size)) {
1422 #else
1423   /* Check if Range header was respected. */
1424   if (src->ret == GST_FLOW_CUSTOM_ERROR &&
1425       src->read_position && msg->status_code != SOUP_STATUS_PARTIAL_CONTENT) {
1426 #endif
1427     src->seekable = FALSE;
1428     GST_ELEMENT_ERROR (src, RESOURCE, SEEK,
1429         (_("Server does not support seeking.")),
1430         ("Server does not accept Range HTTP header, URL: %s, Redirect to: %s",
1431             src->location, GST_STR_NULL (src->redirection_uri)));
1432     src->ret = GST_FLOW_ERROR;
1433   }
1434
1435   /* If we are going to error out, stop all processing right here, so we
1436    * don't output any data (such as an error html page), and return
1437    * GST_FLOW_ERROR from the create function instead of having
1438    * got_chunk_cb overwrite src->ret with FLOW_OK again. */
1439   if (src->ret == GST_FLOW_ERROR || src->ret == GST_FLOW_EOS) {
1440     gst_soup_http_src_session_pause_message (src);
1441
1442     if (src->loop)
1443       g_main_loop_quit (src->loop);
1444   }
1445   g_cond_signal (&src->request_finished_cond);
1446 }
1447
1448 /* Have body. Signal EOS. */
1449 static void
1450 gst_soup_http_src_got_body_cb (SoupMessage * msg, GstSoupHTTPSrc * src)
1451 {
1452   if (G_UNLIKELY (msg != src->msg)) {
1453     GST_DEBUG_OBJECT (src, "got body, but not for current message");
1454     return;
1455   }
1456   if (G_UNLIKELY (src->session_io_status !=
1457           GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING)) {
1458     /* Probably a redirect. */
1459     return;
1460   }
1461   GST_DEBUG_OBJECT (src, "got body");
1462   src->ret = GST_FLOW_EOS;
1463   src->have_body = TRUE;
1464
1465   /* no need to interrupt the message here, we do it on the
1466    * finished_cb anyway if needed. And getting the body might mean
1467    * that the connection was hang up before finished. This happens when
1468    * the pipeline is stalled for too long (long pauses during playback).
1469    * Best to let it continue from here and pause because it reached the
1470    * final bytes based on content_size or received an out of range error */
1471 }
1472
1473 /* Finished. Signal EOS. */
1474 static void
1475 gst_soup_http_src_finished_cb (SoupMessage * msg, GstSoupHTTPSrc * src)
1476 {
1477   if (G_UNLIKELY (msg != src->msg)) {
1478     GST_DEBUG_OBJECT (src, "finished, but not for current message");
1479     return;
1480   }
1481   GST_INFO_OBJECT (src, "finished, io status: %d", src->session_io_status);
1482   src->ret = GST_FLOW_EOS;
1483   if (src->session_io_status == GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_CANCELLED) {
1484     /* gst_soup_http_src_cancel_message() triggered this; probably a seek
1485      * that occurred in the QUEUEING state; i.e. before the connection setup
1486      * was complete. Do nothing */
1487     GST_DEBUG_OBJECT (src, "cancelled");
1488   } else if (src->session_io_status ==
1489       GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING && src->read_position > 0 &&
1490       (src->have_size && src->read_position < src->content_size) &&
1491       (src->max_retries == -1 || src->retry_count < src->max_retries)) {
1492     /* The server disconnected while streaming. Reconnect and seeking to the
1493      * last location. */
1494     src->retry = TRUE;
1495     src->retry_count++;
1496     src->ret = GST_FLOW_CUSTOM_ERROR;
1497   } else if (G_UNLIKELY (src->session_io_status !=
1498           GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING)) {
1499     if (msg->method == SOUP_METHOD_HEAD) {
1500       GST_DEBUG_OBJECT (src, "Ignoring error %d:%s during HEAD request",
1501           msg->status_code, msg->reason_phrase);
1502     } else {
1503       gst_soup_http_src_parse_status (msg, src);
1504     }
1505   }
1506   if (src->loop)
1507     g_main_loop_quit (src->loop);
1508   g_cond_signal (&src->request_finished_cond);
1509 }
1510
1511 /* Buffer lifecycle management.
1512  *
1513  * gst_soup_http_src_create() runs the GMainLoop for this element, to let
1514  * Soup take control.
1515  * A GstBuffer is allocated in gst_soup_http_src_chunk_allocator() and
1516  * associated with a SoupBuffer.
1517  * Soup reads HTTP data in the GstBuffer's data buffer.
1518  * The gst_soup_http_src_got_chunk_cb() is then called with the SoupBuffer.
1519  * That sets gst_soup_http_src_create()'s return argument to the GstBuffer,
1520  * increments its refcount (to 2), pauses the flow of data from the HTTP
1521  * source to prevent gst_soup_http_src_got_chunk_cb() from being called
1522  * again and breaks out of the GMainLoop.
1523  * Because the SOUP_MESSAGE_OVERWRITE_CHUNKS flag is set, Soup frees the
1524  * SoupBuffer and calls gst_soup_http_src_chunk_free(), which decrements the
1525  * refcount (to 1).
1526  * gst_soup_http_src_create() returns the GstBuffer. It will be freed by a
1527  * downstream element.
1528  * If Soup fails to read HTTP data, it does not call
1529  * gst_soup_http_src_got_chunk_cb(), but still frees the SoupBuffer and
1530  * calls gst_soup_http_src_chunk_free(), which decrements the GstBuffer's
1531  * refcount to 0, freeing it.
1532  */
1533
1534 typedef struct
1535 {
1536   GstBuffer *buffer;
1537   GstMapInfo map;
1538 } SoupGstChunk;
1539
1540 static void
1541 gst_soup_http_src_chunk_free (gpointer user_data)
1542 {
1543   SoupGstChunk *chunk = (SoupGstChunk *) user_data;
1544
1545   gst_buffer_unmap (chunk->buffer, &chunk->map);
1546   gst_buffer_unref (chunk->buffer);
1547   g_slice_free (SoupGstChunk, chunk);
1548 }
1549
1550 static SoupBuffer *
1551 gst_soup_http_src_chunk_allocator (SoupMessage * msg, gsize max_len,
1552     gpointer user_data)
1553 {
1554   GstSoupHTTPSrc *src = (GstSoupHTTPSrc *) user_data;
1555   GstBaseSrc *basesrc = GST_BASE_SRC_CAST (src);
1556   GstBuffer *gstbuf;
1557   SoupBuffer *soupbuf;
1558   gsize length;
1559   GstFlowReturn rc;
1560   SoupGstChunk *chunk;
1561
1562   if (max_len)
1563     length = MIN (basesrc->blocksize, max_len);
1564   else
1565     length = basesrc->blocksize;
1566   GST_DEBUG_OBJECT (src, "alloc %" G_GSIZE_FORMAT " bytes <= %" G_GSIZE_FORMAT,
1567       length, max_len);
1568
1569   rc = GST_BASE_SRC_CLASS (parent_class)->alloc (basesrc, -1, length, &gstbuf);
1570   if (G_UNLIKELY (rc != GST_FLOW_OK)) {
1571     /* Failed to allocate buffer. Stall SoupSession and return error code
1572      * to create(). */
1573     src->ret = rc;
1574     g_main_loop_quit (src->loop);
1575     return NULL;
1576   }
1577
1578   chunk = g_slice_new0 (SoupGstChunk);
1579   chunk->buffer = gstbuf;
1580   gst_buffer_map (gstbuf, &chunk->map, GST_MAP_READWRITE);
1581
1582   soupbuf = soup_buffer_new_with_owner (chunk->map.data, chunk->map.size,
1583       chunk, gst_soup_http_src_chunk_free);
1584
1585   return soupbuf;
1586 }
1587
1588 static void
1589 gst_soup_http_src_got_chunk_cb (SoupMessage * msg, SoupBuffer * chunk,
1590     GstSoupHTTPSrc * src)
1591 {
1592   GstBaseSrc *basesrc;
1593   guint64 new_position;
1594   SoupGstChunk *gchunk;
1595
1596   if (G_UNLIKELY (msg != src->msg)) {
1597     GST_DEBUG_OBJECT (src, "got chunk, but not for current message");
1598     return;
1599   }
1600   if (G_UNLIKELY (!src->outbuf)) {
1601     GST_DEBUG_OBJECT (src, "got chunk but we're not expecting one");
1602     src->ret = GST_FLOW_OK;
1603     gst_soup_http_src_cancel_message (src);
1604     g_main_loop_quit (src->loop);
1605     return;
1606   }
1607
1608   /* We got data, reset the retry counter */
1609   src->retry_count = 0;
1610
1611   src->have_body = FALSE;
1612   if (G_UNLIKELY (src->session_io_status !=
1613           GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING)) {
1614     /* Probably a redirect. */
1615     return;
1616   }
1617   basesrc = GST_BASE_SRC_CAST (src);
1618   GST_DEBUG_OBJECT (src, "got chunk of %" G_GSIZE_FORMAT " bytes",
1619       chunk->length);
1620
1621   /* Extract the GstBuffer from the SoupBuffer and set its fields. */
1622   gchunk = (SoupGstChunk *) soup_buffer_get_owner (chunk);
1623   *src->outbuf = gchunk->buffer;
1624
1625   gst_buffer_resize (*src->outbuf, 0, chunk->length);
1626   GST_BUFFER_OFFSET (*src->outbuf) = basesrc->segment.position;
1627
1628   gst_buffer_ref (*src->outbuf);
1629
1630   new_position = src->read_position + chunk->length;
1631   if (G_LIKELY (src->request_position == src->read_position))
1632     src->request_position = new_position;
1633   src->read_position = new_position;
1634
1635   if (src->have_size) {
1636     if (new_position > src->content_size) {
1637       GST_DEBUG_OBJECT (src, "Got position previous estimated content size "
1638           "(%" G_GINT64_FORMAT " > %" G_GINT64_FORMAT ")", new_position,
1639           src->content_size);
1640       src->content_size = new_position;
1641       basesrc->segment.duration = src->content_size;
1642       gst_element_post_message (GST_ELEMENT (src),
1643           gst_message_new_duration_changed (GST_OBJECT (src)));
1644     } else if (new_position == src->content_size) {
1645       GST_DEBUG_OBJECT (src, "We're EOS now");
1646     }
1647   }
1648
1649   src->ret = GST_FLOW_OK;
1650   g_main_loop_quit (src->loop);
1651   gst_soup_http_src_session_pause_message (src);
1652 }
1653
1654 static void
1655 gst_soup_http_src_response_cb (SoupSession * session, SoupMessage * msg,
1656     GstSoupHTTPSrc * src)
1657 {
1658   if (G_UNLIKELY (msg != src->msg)) {
1659     GST_DEBUG_OBJECT (src, "got response %d: %s, but not for current message",
1660         msg->status_code, msg->reason_phrase);
1661     return;
1662   }
1663   if (G_UNLIKELY (src->session_io_status !=
1664           GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING)
1665       && SOUP_STATUS_IS_REDIRECTION (msg->status_code)) {
1666     /* Ignore redirections. */
1667     return;
1668   }
1669   GST_INFO_OBJECT (src, "got response %d: %s", msg->status_code,
1670       msg->reason_phrase);
1671   if (src->session_io_status == GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING &&
1672       src->read_position > 0 && (src->have_size
1673           && src->read_position < src->content_size) &&
1674       (src->max_retries == -1 || src->retry_count < src->max_retries)) {
1675     /* The server disconnected while streaming. Reconnect and seeking to the
1676      * last location. */
1677     src->retry = TRUE;
1678     src->retry_count++;
1679   } else {
1680     gst_soup_http_src_parse_status (msg, src);
1681   }
1682   /* The session's SoupMessage object expires after this callback returns. */
1683   src->msg = NULL;
1684   g_main_loop_quit (src->loop);
1685 }
1686
1687 #define SOUP_HTTP_SRC_ERROR(src,soup_msg,cat,code,error_message)     \
1688   GST_ELEMENT_ERROR ((src), cat, code, ("%s", error_message),        \
1689       ("%s (%d), URL: %s, Redirect to: %s", (soup_msg)->reason_phrase,                \
1690           (soup_msg)->status_code, (src)->location, GST_STR_NULL ((src)->redirection_uri)));
1691
1692 static void
1693 gst_soup_http_src_parse_status (SoupMessage * msg, GstSoupHTTPSrc * src)
1694 {
1695   if (msg->method == SOUP_METHOD_HEAD) {
1696     if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
1697       GST_DEBUG_OBJECT (src, "Ignoring error %d during HEAD request",
1698           msg->status_code);
1699   } else if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code)) {
1700     switch (msg->status_code) {
1701       case SOUP_STATUS_CANT_RESOLVE:
1702       case SOUP_STATUS_CANT_RESOLVE_PROXY:
1703         SOUP_HTTP_SRC_ERROR (src, msg, RESOURCE, NOT_FOUND,
1704             _("Could not resolve server name."));
1705         src->ret = GST_FLOW_ERROR;
1706         break;
1707       case SOUP_STATUS_CANT_CONNECT:
1708       case SOUP_STATUS_CANT_CONNECT_PROXY:
1709         SOUP_HTTP_SRC_ERROR (src, msg, RESOURCE, OPEN_READ,
1710             _("Could not establish connection to server."));
1711         src->ret = GST_FLOW_ERROR;
1712         break;
1713       case SOUP_STATUS_SSL_FAILED:
1714         SOUP_HTTP_SRC_ERROR (src, msg, RESOURCE, OPEN_READ,
1715             _("Secure connection setup failed."));
1716         src->ret = GST_FLOW_ERROR;
1717         break;
1718       case SOUP_STATUS_IO_ERROR:
1719         if (src->max_retries == -1 || src->retry_count < src->max_retries) {
1720           src->retry = TRUE;
1721           src->retry_count++;
1722           src->ret = GST_FLOW_CUSTOM_ERROR;
1723         } else {
1724           SOUP_HTTP_SRC_ERROR (src, msg, RESOURCE, READ,
1725               _("A network error occurred, or the server closed the connection "
1726                   "unexpectedly."));
1727           src->ret = GST_FLOW_ERROR;
1728         }
1729         break;
1730       case SOUP_STATUS_MALFORMED:
1731         SOUP_HTTP_SRC_ERROR (src, msg, RESOURCE, READ,
1732             _("Server sent bad data."));
1733         src->ret = GST_FLOW_ERROR;
1734         break;
1735       case SOUP_STATUS_CANCELLED:
1736         /* No error message when interrupted by program. */
1737         break;
1738     }
1739   } else if (SOUP_STATUS_IS_CLIENT_ERROR (msg->status_code) ||
1740       SOUP_STATUS_IS_REDIRECTION (msg->status_code) ||
1741       SOUP_STATUS_IS_SERVER_ERROR (msg->status_code)) {
1742     /* Report HTTP error. */
1743
1744     /* when content_size is unknown and we have just finished receiving
1745      * a body message, requests that go beyond the content limits will result
1746      * in an error. Here we convert those to EOS */
1747 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
1748     if (msg->status_code == SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE &&
1749         ((src->have_body && !src->have_size) ||
1750          (src->have_size && src->request_position >= src->content_size))) {
1751       GST_DEBUG_OBJECT (src, "Requested range out of limits and received full "
1752           "body, returning EOS");
1753       src->ret = GST_FLOW_EOS;
1754       return;
1755     }
1756 #else
1757     if (msg->status_code == SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE &&
1758         src->have_body && !src->have_size) {
1759       GST_DEBUG_OBJECT (src, "Requested range out of limits and received full "
1760           "body, returning EOS");
1761       src->ret = GST_FLOW_EOS;
1762       return;
1763     }
1764 #endif
1765
1766     /* FIXME: reason_phrase is not translated and not suitable for user
1767      * error dialog according to libsoup documentation.
1768      */
1769     if (msg->status_code == SOUP_STATUS_NOT_FOUND) {
1770       GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
1771           ("%s", msg->reason_phrase),
1772           ("%s (%d), URL: %s, Redirect to: %s", msg->reason_phrase,
1773               msg->status_code, src->location,
1774               GST_STR_NULL (src->redirection_uri)));
1775     } else if (msg->status_code == SOUP_STATUS_UNAUTHORIZED
1776         || msg->status_code == SOUP_STATUS_PAYMENT_REQUIRED
1777         || msg->status_code == SOUP_STATUS_FORBIDDEN
1778         || msg->status_code == SOUP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
1779       GST_ELEMENT_ERROR (src, RESOURCE, NOT_AUTHORIZED, ("%s",
1780               msg->reason_phrase), ("%s (%d), URL: %s, Redirect to: %s",
1781               msg->reason_phrase, msg->status_code, src->location,
1782               GST_STR_NULL (src->redirection_uri)));
1783     } else {
1784       GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
1785           ("%s", msg->reason_phrase),
1786           ("%s (%d), URL: %s, Redirect to: %s", msg->reason_phrase,
1787               msg->status_code, src->location,
1788               GST_STR_NULL (src->redirection_uri)));
1789     }
1790     src->ret = GST_FLOW_ERROR;
1791   }
1792 }
1793
1794 static gboolean
1795 gst_soup_http_src_build_message (GstSoupHTTPSrc * src, const gchar * method)
1796 {
1797   g_return_val_if_fail (src->msg == NULL, FALSE);
1798
1799   src->msg = soup_message_new (method, src->location);
1800   if (!src->msg) {
1801     GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ,
1802         ("Error parsing URL."), ("URL: %s", src->location));
1803     return FALSE;
1804   }
1805   src->session_io_status = GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_IDLE;
1806   if (!src->keep_alive) {
1807     soup_message_headers_append (src->msg->request_headers, "Connection",
1808         "close");
1809   }
1810   if (src->iradio_mode) {
1811     soup_message_headers_append (src->msg->request_headers, "icy-metadata",
1812         "1");
1813   }
1814
1815 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
1816 /*[prasenjit.c]This changes are needed to enable Seekable Contents from server.
1817 We have observed that , for few specific networks ( VODAFONE ) , without theabove headers ,
1818 Youtube is sending non-seekable contents to the Client.
1819 */
1820   soup_message_headers_append (src->msg->request_headers, "Accept-Ranges","bytes");
1821
1822   if (src->cookie_jar) {
1823     GSList *cookie_list, *c;
1824     gchar *header;
1825
1826     SoupURI *uri = NULL;
1827     SoupCookie *cookie;
1828     uri = soup_uri_new (src->location);
1829
1830     if ((cookie_list = soup_cookie_jar_all_cookies (src->cookie_jar)) != NULL) {
1831       for (c = cookie_list; c; c = c->next) {
1832         cookie = (SoupCookie *)c->data;
1833         if (soup_cookie_applies_to_uri(cookie, uri)) {
1834           header = soup_cookie_to_cookie_header (cookie);
1835           soup_message_headers_append (src->msg->request_headers, "Cookie", header);
1836           g_free (header);
1837         }
1838       }
1839     }
1840     soup_cookies_free (cookie_list);
1841     soup_uri_free (uri);
1842   }
1843 #else
1844   if (src->cookies) {
1845     gchar **cookie;
1846
1847     for (cookie = src->cookies; *cookie != NULL; cookie++) {
1848       soup_message_headers_append (src->msg->request_headers, "Cookie",
1849           *cookie);
1850     }
1851   }
1852 #endif
1853
1854   src->retry = FALSE;
1855
1856   g_signal_connect (src->msg, "got_headers",
1857       G_CALLBACK (gst_soup_http_src_got_headers_cb), src);
1858   g_signal_connect (src->msg, "got_body",
1859       G_CALLBACK (gst_soup_http_src_got_body_cb), src);
1860   g_signal_connect (src->msg, "finished",
1861       G_CALLBACK (gst_soup_http_src_finished_cb), src);
1862   g_signal_connect (src->msg, "got_chunk",
1863       G_CALLBACK (gst_soup_http_src_got_chunk_cb), src);
1864   soup_message_set_flags (src->msg, SOUP_MESSAGE_OVERWRITE_CHUNKS |
1865       (src->automatic_redirect ? 0 : SOUP_MESSAGE_NO_REDIRECT));
1866   soup_message_set_chunk_allocator (src->msg,
1867       gst_soup_http_src_chunk_allocator, src, NULL);
1868   gst_soup_http_src_add_range_header (src, src->request_position,
1869       src->stop_position);
1870
1871   gst_soup_http_src_add_extra_headers (src);
1872
1873 #ifdef TIZEN_FEATURE_SOUP_MODIFICATION
1874   soup_message_headers_foreach (src->msg->request_headers,
1875       gst_soup_http_src_headers_foreach, src);
1876 #endif
1877
1878   return TRUE;
1879 }
1880
1881 static GstFlowReturn
1882 gst_soup_http_src_do_request (GstSoupHTTPSrc * src, const gchar * method,
1883     GstBuffer ** outbuf)
1884 {
1885   /* If we're not OK, just go out of here */
1886   if (src->ret != GST_FLOW_OK) {
1887     GST_DEBUG_OBJECT (src, "Previous flow return not OK: %s",
1888         gst_flow_get_name (src->ret));
1889     return src->ret;
1890   }
1891
1892   GST_LOG_OBJECT (src, "Running request for method: %s", method);
1893   if (src->msg && (src->request_position != src->read_position)) {
1894     if (src->session_io_status == GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_IDLE) {
1895       gst_soup_http_src_add_range_header (src, src->request_position,
1896           src->stop_position);
1897     } else {
1898       GST_DEBUG_OBJECT (src, "Seek from position %" G_GUINT64_FORMAT
1899           " to %" G_GUINT64_FORMAT ": requeueing connection request",
1900           src->read_position, src->request_position);
1901       gst_soup_http_src_cancel_message (src);
1902     }
1903   }
1904   if (!src->msg)
1905     if (!gst_soup_http_src_build_message (src, method)) {
1906       return GST_FLOW_ERROR;
1907     }
1908
1909   src->ret = GST_FLOW_CUSTOM_ERROR;
1910   src->outbuf = outbuf;
1911   do {
1912     if (src->interrupted) {
1913       GST_INFO_OBJECT (src, "interrupted");
1914       src->ret = GST_FLOW_FLUSHING;
1915       break;
1916     }
1917     if (src->retry) {
1918       GST_INFO_OBJECT (src, "Reconnecting");
1919       if (!gst_soup_http_src_build_message (src, method)) {
1920         return GST_FLOW_ERROR;
1921       }
1922       src->retry = FALSE;
1923       continue;
1924     }
1925     if (!src->msg) {
1926       GST_DEBUG_OBJECT (src, "EOS reached");
1927       break;
1928     }
1929
1930     switch (src->session_io_status) {
1931       case GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_IDLE:
1932         GST_INFO_OBJECT (src, "Queueing connection request");
1933         gst_soup_http_src_queue_message (src);
1934         break;
1935       case GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_QUEUED:
1936         break;
1937       case GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_RUNNING:
1938         gst_soup_http_src_session_unpause_message (src);
1939         break;
1940       case GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_CANCELLED:
1941         /* Impossible. */
1942         break;
1943     }
1944
1945     if (src->ret == GST_FLOW_CUSTOM_ERROR) {
1946       g_main_context_push_thread_default (src->context);
1947       g_main_loop_run (src->loop);
1948       g_main_context_pop_thread_default (src->context);
1949     }
1950
1951   } while (src->ret == GST_FLOW_CUSTOM_ERROR);
1952
1953   /* Let the request finish if we had a stop position and are there */
1954   if (src->ret == GST_FLOW_OK && src->stop_position != -1
1955       && src->read_position >= src->stop_position) {
1956     src->outbuf = NULL;
1957     gst_soup_http_src_session_unpause_message (src);
1958     g_main_context_push_thread_default (src->context);
1959     g_main_loop_run (src->loop);
1960     g_main_context_pop_thread_default (src->context);
1961
1962     g_cond_signal (&src->request_finished_cond);
1963     /* Return OK unconditionally here, src->ret will
1964      * be most likely be EOS now but we want to
1965      * consume the buffer we got above */
1966     return GST_FLOW_OK;
1967   }
1968
1969   if (src->ret == GST_FLOW_CUSTOM_ERROR)
1970     src->ret = GST_FLOW_EOS;
1971   g_cond_signal (&src->request_finished_cond);
1972
1973   /* basesrc assumes that we don't return a buffer if
1974    * something else than OK is returned. It will just
1975    * leak any buffer we might accidentially provide
1976    * here.
1977    *
1978    * This can potentially happen during flushing.
1979    */
1980   if (src->ret != GST_FLOW_OK && outbuf && *outbuf) {
1981     gst_buffer_unref (*outbuf);
1982     *outbuf = NULL;
1983   }
1984
1985   return src->ret;
1986 }
1987
1988 static GstFlowReturn
1989 gst_soup_http_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
1990 {
1991   GstSoupHTTPSrc *src;
1992   GstFlowReturn ret;
1993   GstEvent *http_headers_event;
1994
1995   src = GST_SOUP_HTTP_SRC (psrc);
1996
1997   g_mutex_lock (&src->mutex);
1998   *outbuf = NULL;
1999   ret =
2000       gst_soup_http_src_do_request (src,
2001       src->method ? src->method : SOUP_METHOD_GET, outbuf);
2002   http_headers_event = src->http_headers_event;
2003   src->http_headers_event = NULL;
2004   g_mutex_unlock (&src->mutex);
2005
2006   if (http_headers_event)
2007     gst_pad_push_event (GST_BASE_SRC_PAD (src), http_headers_event);
2008
2009   return ret;
2010 }
2011
2012 static gboolean
2013 gst_soup_http_src_start (GstBaseSrc * bsrc)
2014 {
2015   GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (bsrc);
2016
2017   GST_DEBUG_OBJECT (src, "start(\"%s\")", src->location);
2018
2019   return gst_soup_http_src_session_open (src);
2020 }
2021
2022 static gboolean
2023 gst_soup_http_src_stop (GstBaseSrc * bsrc)
2024 {
2025   GstSoupHTTPSrc *src;
2026
2027   src = GST_SOUP_HTTP_SRC (bsrc);
2028   GST_DEBUG_OBJECT (src, "stop()");
2029   if (src->keep_alive && !src->msg)
2030     gst_soup_http_src_cancel_message (src);
2031   else
2032     gst_soup_http_src_session_close (src);
2033
2034   gst_soup_http_src_reset (src);
2035   return TRUE;
2036 }
2037
2038 static GstStateChangeReturn
2039 gst_soup_http_src_change_state (GstElement * element, GstStateChange transition)
2040 {
2041   GstStateChangeReturn ret;
2042   GstSoupHTTPSrc *src;
2043
2044   src = GST_SOUP_HTTP_SRC (element);
2045
2046   switch (transition) {
2047     case GST_STATE_CHANGE_READY_TO_NULL:
2048       gst_soup_http_src_session_close (src);
2049       break;
2050     default:
2051       break;
2052   }
2053
2054   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
2055
2056   return ret;
2057 }
2058
2059 /* Interrupt a blocking request. */
2060 static gboolean
2061 gst_soup_http_src_unlock (GstBaseSrc * bsrc)
2062 {
2063   GstSoupHTTPSrc *src;
2064
2065   src = GST_SOUP_HTTP_SRC (bsrc);
2066   GST_DEBUG_OBJECT (src, "unlock()");
2067
2068   src->interrupted = TRUE;
2069   src->ret = GST_FLOW_FLUSHING;
2070   if (src->loop)
2071     g_main_loop_quit (src->loop);
2072   g_cond_signal (&src->request_finished_cond);
2073   return TRUE;
2074 }
2075
2076 /* Interrupt interrupt. */
2077 static gboolean
2078 gst_soup_http_src_unlock_stop (GstBaseSrc * bsrc)
2079 {
2080   GstSoupHTTPSrc *src;
2081
2082   src = GST_SOUP_HTTP_SRC (bsrc);
2083   GST_DEBUG_OBJECT (src, "unlock_stop()");
2084
2085   src->interrupted = FALSE;
2086   src->ret = GST_FLOW_OK;
2087   return TRUE;
2088 }
2089
2090 static gboolean
2091 gst_soup_http_src_get_size (GstBaseSrc * bsrc, guint64 * size)
2092 {
2093   GstSoupHTTPSrc *src;
2094
2095   src = GST_SOUP_HTTP_SRC (bsrc);
2096
2097   if (src->have_size) {
2098     GST_DEBUG_OBJECT (src, "get_size() = %" G_GUINT64_FORMAT,
2099         src->content_size);
2100     *size = src->content_size;
2101     return TRUE;
2102   }
2103   GST_DEBUG_OBJECT (src, "get_size() = FALSE");
2104   return FALSE;
2105 }
2106
2107 static void
2108 gst_soup_http_src_check_seekable (GstSoupHTTPSrc * src)
2109 {
2110   GstFlowReturn ret = GST_FLOW_OK;
2111
2112   /* Special case to check if the server allows range requests
2113    * before really starting to get data in the buffer creation
2114    * loops.
2115    */
2116   if (!src->got_headers && GST_STATE (src) >= GST_STATE_PAUSED) {
2117     g_mutex_lock (&src->mutex);
2118     while (!src->got_headers && !src->interrupted && ret == GST_FLOW_OK) {
2119       if ((src->msg && src->msg->method != SOUP_METHOD_HEAD) &&
2120           src->session_io_status != GST_SOUP_HTTP_SRC_SESSION_IO_STATUS_IDLE) {
2121         /* wait for the current request to finish */
2122         g_cond_wait (&src->request_finished_cond, &src->mutex);
2123       } else {
2124         if (gst_soup_http_src_session_open (src)) {
2125           ret = gst_soup_http_src_do_request (src, SOUP_METHOD_HEAD, NULL);
2126         }
2127       }
2128     }
2129     if (src->ret == GST_FLOW_EOS) {
2130       /* A HEAD request shouldn't lead to EOS */
2131       src->ret = GST_FLOW_OK;
2132     }
2133     /* resets status to idle */
2134     gst_soup_http_src_cancel_message (src);
2135     g_mutex_unlock (&src->mutex);
2136   }
2137 }
2138
2139 static gboolean
2140 gst_soup_http_src_is_seekable (GstBaseSrc * bsrc)
2141 {
2142   GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (bsrc);
2143
2144   gst_soup_http_src_check_seekable (src);
2145
2146   return src->seekable;
2147 }
2148
2149 static gboolean
2150 gst_soup_http_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
2151 {
2152   GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (bsrc);
2153
2154   GST_DEBUG_OBJECT (src, "do_seek(%" G_GUINT64_FORMAT "-%" G_GUINT64_FORMAT
2155       ")", segment->start, segment->stop);
2156   if (src->read_position == segment->start &&
2157       src->request_position == src->read_position &&
2158       src->stop_position == segment->stop) {
2159     GST_DEBUG_OBJECT (src,
2160         "Seek to current read/end position and no seek pending");
2161     return TRUE;
2162   }
2163
2164   gst_soup_http_src_check_seekable (src);
2165
2166   /* If we have no headers we don't know yet if it is seekable or not.
2167    * Store the start position and error out later if it isn't */
2168   if (src->got_headers && !src->seekable) {
2169     GST_WARNING_OBJECT (src, "Not seekable");
2170     return FALSE;
2171   }
2172
2173   if (segment->rate < 0.0 || segment->format != GST_FORMAT_BYTES) {
2174     GST_WARNING_OBJECT (src, "Invalid seek segment");
2175     return FALSE;
2176   }
2177
2178   if (src->have_size && segment->start >= src->content_size) {
2179     GST_WARNING_OBJECT (src,
2180         "Potentially seeking behind end of file, might EOS immediately");
2181   }
2182
2183   /* Wait for create() to handle the jump in offset. */
2184   src->request_position = segment->start;
2185   src->stop_position = segment->stop;
2186
2187   return TRUE;
2188 }
2189
2190 static gboolean
2191 gst_soup_http_src_query (GstBaseSrc * bsrc, GstQuery * query)
2192 {
2193   GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (bsrc);
2194   gboolean ret;
2195   GstSchedulingFlags flags;
2196   gint minsize, maxsize, align;
2197
2198   switch (GST_QUERY_TYPE (query)) {
2199     case GST_QUERY_URI:
2200       gst_query_set_uri (query, src->location);
2201       if (src->redirection_uri != NULL) {
2202         gst_query_set_uri_redirection (query, src->redirection_uri);
2203         gst_query_set_uri_redirection_permanent (query,
2204             src->redirection_permanent);
2205       }
2206       ret = TRUE;
2207       break;
2208     default:
2209       ret = FALSE;
2210       break;
2211   }
2212
2213   if (!ret)
2214     ret = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
2215
2216   switch (GST_QUERY_TYPE (query)) {
2217     case GST_QUERY_SCHEDULING:
2218       gst_query_parse_scheduling (query, &flags, &minsize, &maxsize, &align);
2219       flags |= GST_SCHEDULING_FLAG_BANDWIDTH_LIMITED;
2220       gst_query_set_scheduling (query, flags, minsize, maxsize, align);
2221       break;
2222     default:
2223       break;
2224   }
2225
2226   return ret;
2227 }
2228
2229 static gboolean
2230 gst_soup_http_src_set_location (GstSoupHTTPSrc * src, const gchar * uri,
2231     GError ** error)
2232 {
2233   const char *alt_schemes[] = { "icy://", "icyx://" };
2234   guint i;
2235
2236   if (src->location) {
2237     g_free (src->location);
2238     src->location = NULL;
2239   }
2240
2241   if (uri == NULL)
2242     return FALSE;
2243
2244   for (i = 0; i < G_N_ELEMENTS (alt_schemes); i++) {
2245     if (g_str_has_prefix (uri, alt_schemes[i])) {
2246       src->location =
2247           g_strdup_printf ("http://%s", uri + strlen (alt_schemes[i]));
2248       return TRUE;
2249     }
2250   }
2251
2252   if (src->redirection_uri) {
2253     g_free (src->redirection_uri);
2254     src->redirection_uri = NULL;
2255   }
2256
2257   src->location = g_strdup (uri);
2258
2259   return TRUE;
2260 }
2261
2262 static gboolean
2263 gst_soup_http_src_set_proxy (GstSoupHTTPSrc * src, const gchar * uri)
2264 {
2265   if (src->proxy) {
2266     soup_uri_free (src->proxy);
2267     src->proxy = NULL;
2268   }
2269
2270   if (uri == NULL || *uri == '\0')
2271     return TRUE;
2272
2273   if (g_str_has_prefix (uri, "http://")) {
2274     src->proxy = soup_uri_new (uri);
2275   } else {
2276     gchar *new_uri = g_strconcat ("http://", uri, NULL);
2277
2278     src->proxy = soup_uri_new (new_uri);
2279     g_free (new_uri);
2280   }
2281
2282   return (src->proxy != NULL);
2283 }
2284
2285 static guint
2286 gst_soup_http_src_uri_get_type (GType type)
2287 {
2288   return GST_URI_SRC;
2289 }
2290
2291 static const gchar *const *
2292 gst_soup_http_src_uri_get_protocols (GType type)
2293 {
2294   static const gchar *protocols[] = { "http", "https", "icy", "icyx", NULL };
2295
2296   return protocols;
2297 }
2298
2299 static gchar *
2300 gst_soup_http_src_uri_get_uri (GstURIHandler * handler)
2301 {
2302   GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (handler);
2303
2304   /* FIXME: make thread-safe */
2305   return g_strdup (src->location);
2306 }
2307
2308 static gboolean
2309 gst_soup_http_src_uri_set_uri (GstURIHandler * handler, const gchar * uri,
2310     GError ** error)
2311 {
2312   GstSoupHTTPSrc *src = GST_SOUP_HTTP_SRC (handler);
2313
2314   return gst_soup_http_src_set_location (src, uri, error);
2315 }
2316
2317 static void
2318 gst_soup_http_src_uri_handler_init (gpointer g_iface, gpointer iface_data)
2319 {
2320   GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface;
2321
2322   iface->get_type = gst_soup_http_src_uri_get_type;
2323   iface->get_protocols = gst_soup_http_src_uri_get_protocols;
2324   iface->get_uri = gst_soup_http_src_uri_get_uri;
2325   iface->set_uri = gst_soup_http_src_uri_set_uri;
2326 }