ext/neon/gstneonhttpsrc.*: Simplify _set_uri() and _set_proxy() and remove the unused ishttp member (#388050).

Original commit message from CVS:
Patch by: Lutz Mueller  <lutz topfrose de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_set_property),
(gst_neonhttp_src_set_uri), (gst_neonhttp_src_set_proxy),
(gst_neonhttp_src_send_request_and_redirect),
(gst_neonhttp_src_uri_set_uri):
* ext/neon/gstneonhttpsrc.h:
Simplify _set_uri() and _set_proxy() and remove the unused ishttp
member (#388050).
* tests/check/elements/neonhttpsrc.c: (GST_START_TEST):
Fix bogus URI to something that actually exists, otherwise we just
bypass the test (and also to something that doesn't redirect, since
neonhttpsrc doesn't seem to handle this very gracefully yet)
This commit is contained in:
Lutz Mueller 2007-03-02 12:04:02 +00:00 committed by Tim-Philipp Müller
parent 3bdee19bad
commit 6ffee3230a
4 changed files with 81 additions and 87 deletions

View File

@ -1,3 +1,21 @@
2007-03-02 Tim-Philipp Müller <tim at centricular dot net>
Patch by: Lutz Mueller <lutz topfrose de>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_class_init),
(gst_neonhttp_src_init), (gst_neonhttp_src_set_property),
(gst_neonhttp_src_set_uri), (gst_neonhttp_src_set_proxy),
(gst_neonhttp_src_send_request_and_redirect),
(gst_neonhttp_src_uri_set_uri):
* ext/neon/gstneonhttpsrc.h:
Simplify _set_uri() and _set_proxy() and remove the unused ishttp
member (#388050).
* tests/check/elements/neonhttpsrc.c: (GST_START_TEST):
Fix bogus URI to something that actually exists, otherwise we just
bypass the test (and also to something that doesn't redirect, since
neonhttpsrc doesn't seem to handle this very gracefully yet)
2007-03-01 Chris Lord <chris@openedhand.com> 2007-03-01 Chris Lord <chris@openedhand.com>
Reviewed by Christian Schaller <christian@fluendo.com> Reviewed by Christian Schaller <christian@fluendo.com>

View File

@ -31,6 +31,8 @@
#define HTTP_DEFAULT_HOST "localhost" #define HTTP_DEFAULT_HOST "localhost"
#define HTTP_DEFAULT_PORT 80 #define HTTP_DEFAULT_PORT 80
#define HTTPS_DEFAULT_PORT 443 #define HTTPS_DEFAULT_PORT 443
#define HTTP_DEFAULT_URI "http://localhost:80/"
#define NEON_HTTP_DEBUG_DEFAULT FALSE
#define HTTP_SOCKET_ERROR -2 #define HTTP_SOCKET_ERROR -2
#define HTTP_REQUEST_WRONG_PROXY -1 #define HTTP_REQUEST_WRONG_PROXY -1
@ -90,10 +92,9 @@ static gboolean gst_neonhttp_src_do_seek (GstBaseSrc * bsrc,
GstSegment * segment); GstSegment * segment);
static gboolean gst_neonhttp_src_set_proxy (GstNeonhttpSrc * src, static gboolean gst_neonhttp_src_set_proxy (GstNeonhttpSrc * src,
const gchar * uri, ne_uri * parsed, gboolean set_default); const gchar * uri);
static gboolean gst_neonhttp_src_set_uri (GstNeonhttpSrc * src, static gboolean gst_neonhttp_src_set_uri (GstNeonhttpSrc * src,
const gchar * uri, ne_uri * parsed, gboolean * ishttps, gchar ** uristr, const gchar * uri);
gboolean set_default);
static gint gst_neonhttp_src_send_request_and_redirect (GstNeonhttpSrc * src, static gint gst_neonhttp_src_send_request_and_redirect (GstNeonhttpSrc * src,
ne_session ** ses, ne_request ** req, gint64 offset, gboolean do_redir); ne_session ** ses, ne_request ** req, gint64 offset, gboolean do_redir);
static gint gst_neonhttp_src_request_dispatch (GstNeonhttpSrc * src, static gint gst_neonhttp_src_request_dispatch (GstNeonhttpSrc * src,
@ -209,7 +210,8 @@ gst_neonhttp_src_class_init (GstNeonhttpSrcClass * klass)
g_object_class_install_property g_object_class_install_property
(gobject_class, PROP_NEON_HTTP_DBG, (gobject_class, PROP_NEON_HTTP_DBG,
g_param_spec_boolean ("neon-http-debug", "neon-http-debug", g_param_spec_boolean ("neon-http-debug", "neon-http-debug",
"Enable Neon HTTP debug messages", FALSE, G_PARAM_READWRITE)); "Enable Neon HTTP debug messages",
NEON_HTTP_DEBUG_DEFAULT, G_PARAM_READWRITE));
#endif #endif
gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_neonhttp_src_start); gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_neonhttp_src_start);
@ -228,14 +230,30 @@ gst_neonhttp_src_class_init (GstNeonhttpSrcClass * klass)
static void static void
gst_neonhttp_src_init (GstNeonhttpSrc * src, GstNeonhttpSrcClass * g_class) gst_neonhttp_src_init (GstNeonhttpSrc * src, GstNeonhttpSrcClass * g_class)
{ {
const gchar *str = g_getenv ("http_proxy");
src->neon_http_msgs_dbg = NEON_HTTP_DEBUG_DEFAULT;
src->session = NULL;
src->request = NULL;
memset (&src->uri, 0, sizeof (src->uri)); memset (&src->uri, 0, sizeof (src->uri));
memset (&src->proxy, 0, sizeof (src->proxy)); memset (&src->proxy, 0, sizeof (src->proxy));
src->content_size = -1; src->content_size = -1;
src->uristr = NULL;
gst_neonhttp_src_set_uri (src, NULL, &src->uri, &src->ishttps, &src->uristr, gst_neonhttp_src_set_uri (src, HTTP_DEFAULT_URI);
TRUE); if (str && !gst_neonhttp_src_set_proxy (src, str)) {
gst_neonhttp_src_set_proxy (src, NULL, &src->proxy, TRUE); GST_WARNING_OBJECT (src,
"The proxy set on http_proxy env var ('%s') cannot be parsed.", str);
}
src->user_agent = g_strdup ("neonhttpsrc");
src->iradio_mode = FALSE;
src->iradio_name = NULL;
src->iradio_genre = NULL;
src->iradio_url = NULL;
src->icy_caps = NULL;
src->icy_metaint = 0;
src->user_agent = g_strdup ("neonhttpsrc"); src->user_agent = g_strdup ("neonhttpsrc");
src->seekable = TRUE; src->seekable = TRUE;
} }
@ -289,8 +307,7 @@ gst_neonhttp_src_set_property (GObject * object, guint prop_id,
GST_WARNING ("proxy property cannot be NULL"); GST_WARNING ("proxy property cannot be NULL");
goto done; goto done;
} }
if (!gst_neonhttp_src_set_proxy (src, g_value_get_string (value), if (!gst_neonhttp_src_set_proxy (src, g_value_get_string (value))) {
&src->proxy, FALSE)) {
GST_WARNING ("badly formated proxy"); GST_WARNING ("badly formated proxy");
goto done; goto done;
} }
@ -303,8 +320,7 @@ gst_neonhttp_src_set_property (GObject * object, guint prop_id,
GST_WARNING ("location property cannot be NULL"); GST_WARNING ("location property cannot be NULL");
goto done; goto done;
} }
if (!gst_neonhttp_src_set_uri (src, g_value_get_string (value), &src->uri, if (!gst_neonhttp_src_set_uri (src, g_value_get_string (value))) {
&src->ishttps, &src->uristr, FALSE)) {
GST_WARNING ("badly formated location"); GST_WARNING ("badly formated location");
goto done; goto done;
} }
@ -682,98 +698,69 @@ gst_neonhttp_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
} }
static gboolean static gboolean
gst_neonhttp_src_set_uri (GstNeonhttpSrc * src, const gchar * uri, gst_neonhttp_src_set_uri (GstNeonhttpSrc * src, const gchar * uri)
ne_uri * parsed, gboolean * ishttps, gchar ** uristr, gboolean set_default)
{ {
ne_uri_free (parsed); ne_uri_free (&src->uri);
if (uristr && *uristr) { if (src->uristr) {
ne_free (*uristr); ne_free (src->uristr);
*uristr = NULL; src->uristr = NULL;
} }
if (set_default) { if (ne_uri_parse (uri, &src->uri) != 0)
parsed->scheme = g_strdup ("http");
parsed->host = g_strdup (HTTP_DEFAULT_HOST);
parsed->port = HTTP_DEFAULT_PORT;
parsed->path = g_strdup ("/");
*ishttps = FALSE;
goto done;
}
if (ne_uri_parse (uri, parsed) != 0)
goto parse_error; goto parse_error;
if (parsed->scheme == NULL) { if (src->uri.scheme == NULL)
parsed->scheme = g_strdup ("http"); src->uri.scheme = g_strdup ("http");
*ishttps = FALSE;
} else { if (src->uri.host == NULL)
if (strcmp (parsed->scheme, "https") == 0) src->uri.host = g_strdup (HTTP_DEFAULT_HOST);
*ishttps = TRUE;
if (src->uri.port == 0) {
if (!strcmp (src->uri.scheme, "https"))
src->uri.port = HTTPS_DEFAULT_PORT;
else else
*ishttps = FALSE; src->uri.port = HTTP_DEFAULT_PORT;
} }
if (parsed->host == NULL) if (!src->uri.path)
parsed->host = g_strdup (HTTP_DEFAULT_HOST); src->uri.path = g_strdup ("");
if (parsed->port == 0) { src->uristr = ne_uri_unparse (&src->uri);
if (*ishttps)
parsed->port = HTTPS_DEFAULT_PORT;
else
parsed->port = HTTP_DEFAULT_PORT;
}
if (!parsed->path)
parsed->path = g_strdup ("");
done:
if (uristr)
*uristr = ne_uri_unparse (parsed);
return TRUE; return TRUE;
/* ERRORS */ /* ERRORS */
parse_error: parse_error:
{ {
if (uristr && *uristr) { if (src->uristr) {
ne_free (*uristr); ne_free (src->uristr);
*uristr = NULL; src->uristr = NULL;
} }
ne_uri_free (parsed); ne_uri_free (&src->uri);
return FALSE; return FALSE;
} }
} }
static gboolean static gboolean
gst_neonhttp_src_set_proxy (GstNeonhttpSrc * src, const gchar * uri, gst_neonhttp_src_set_proxy (GstNeonhttpSrc * src, const char *uri)
ne_uri * parsed, gboolean set_default)
{ {
ne_uri_free (parsed); ne_uri_free (&src->proxy);
if (set_default) { if (ne_uri_parse (uri, &src->proxy) != 0)
const gchar *str = g_getenv ("http_proxy");
if (str) {
if (ne_uri_parse (str, parsed) != 0)
goto cannot_parse;
}
return TRUE;
}
if (ne_uri_parse (uri, parsed) != 0)
goto error; goto error;
if (parsed->scheme) if (src->proxy.scheme)
GST_WARNING ("The proxy schema shouldn't be defined"); GST_WARNING ("The proxy schema shouldn't be defined (schema is '%s')",
src->proxy.scheme);
if (parsed->host && !parsed->port) if (src->proxy.host && !src->proxy.port)
goto error; goto error;
#ifdef NEON_026_OR_LATER #ifdef NEON_026_OR_LATER
if (!parsed->path || parsed->userinfo) if (!src->proxy.path || src->proxy.userinfo)
goto error; goto error;
#else #else
if (!parsed->path || parsed->authinfo) if (!src->proxy.path || src->proxy.authinfo)
goto error; goto error;
#endif #endif
return TRUE; return TRUE;
@ -781,16 +768,9 @@ gst_neonhttp_src_set_proxy (GstNeonhttpSrc * src, const gchar * uri,
/* ERRORS */ /* ERRORS */
error: error:
{ {
ne_uri_free (parsed); ne_uri_free (&src->proxy);
return FALSE; return FALSE;
} }
cannot_parse:
{
GST_WARNING_OBJECT (src,
"The proxy set on http_proxy env var isn't well formated");
ne_uri_free (parsed);
return TRUE;
}
} }
/** /**
@ -848,8 +828,7 @@ gst_neonhttp_src_send_request_and_redirect (GstNeonhttpSrc * src,
redir = ne_get_response_header (request, "Location"); redir = ne_get_response_header (request, "Location");
if (redir != NULL) { if (redir != NULL) {
ne_uri_free (&src->uri); ne_uri_free (&src->uri);
gst_neonhttp_src_set_uri (src, redir, &src->uri, &src->ishttps, gst_neonhttp_src_set_uri (src, redir);
&src->uristr, FALSE);
#ifndef GST_DISABLE_GST_DEBUG #ifndef GST_DISABLE_GST_DEBUG
if (src->neon_http_msgs_dbg) if (src->neon_http_msgs_dbg)
GST_LOG_OBJECT (src, GST_LOG_OBJECT (src,
@ -1025,8 +1004,7 @@ gst_neonhttp_src_uri_set_uri (GstURIHandler * handler, const gchar * uri)
{ {
GstNeonhttpSrc *src = GST_NEONHTTP_SRC (handler); GstNeonhttpSrc *src = GST_NEONHTTP_SRC (handler);
return gst_neonhttp_src_set_uri (src, uri, &src->uri, &src->ishttps, return gst_neonhttp_src_set_uri (src, uri);
&src->uristr, FALSE);
} }
static void static void

View File

@ -52,8 +52,6 @@ struct _GstNeonhttpSrc {
ne_uri proxy; ne_uri proxy;
gchar *user_agent; gchar *user_agent;
gboolean ishttps;
guint64 content_size; guint64 content_size;
gboolean eos; gboolean eos;

View File

@ -50,7 +50,7 @@ GST_START_TEST (test_first_buffer_has_offset)
gst_bin_add (GST_BIN (pipe), sink); gst_bin_add (GST_BIN (pipe), sink);
fail_unless (gst_element_link (src, sink)); fail_unless (gst_element_link (src, sink));
g_object_set (src, "location", "http://www.google.comadfadf", NULL); g_object_set (src, "location", "http://gstreamer.freedesktop.org/", NULL);
g_object_set (src, "automatic-redirect", TRUE, NULL); g_object_set (src, "automatic-redirect", TRUE, NULL);
g_object_set (sink, "signal-handoffs", TRUE, NULL); g_object_set (sink, "signal-handoffs", TRUE, NULL);