Commit cac807b6 authored by Lutz Mueller's avatar Lutz Mueller Committed by Wim Taymans
Browse files

gst/rtsp/gstrtspsrc.*: Make sure we can never set an invalid location.

Original commit message from CVS:
Based on patch by: Lutz Mueller <lutz at topfrose dot de>
* gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_class_init),
(gst_rtspsrc_init), (gst_rtspsrc_set_property), (gst_rtspsrc_open),
(gst_rtspsrc_uri_get_uri), (gst_rtspsrc_uri_set_uri):
* gst/rtsp/gstrtspsrc.h:
Make sure we can never set an invalid location.
* gst/rtsp/rtspmessage.c: (rtsp_message_steal_body):
* gst/rtsp/rtspmessage.h:
Added _steal_body method for future use.
* gst/rtsp/rtspurl.c: (rtsp_url_parse), (rtsp_url_free):
Make freeing of NULL url return immediatly.
parent afd156ad
2006-09-18 Wim Taymans <wim@fluendo.com>
Based on patch by: Lutz Mueller <lutz at topfrose dot de>
* gst/rtsp/gstrtspsrc.c: (gst_rtspsrc_class_init),
(gst_rtspsrc_init), (gst_rtspsrc_set_property), (gst_rtspsrc_open),
(gst_rtspsrc_uri_get_uri), (gst_rtspsrc_uri_set_uri):
* gst/rtsp/gstrtspsrc.h:
Make sure we can never set an invalid location.
* gst/rtsp/rtspmessage.c: (rtsp_message_steal_body):
* gst/rtsp/rtspmessage.h:
Added _steal_body method for future use.
* gst/rtsp/rtspurl.c: (rtsp_url_parse), (rtsp_url_free):
Make freeing of NULL url return immediatly.
2006-09-18 Wim Taymans <wim@fluendo.com>
Based on patch by: Lutz Mueller <lutz at topfrose dot de>
......
......@@ -147,6 +147,9 @@ static void gst_rtspsrc_set_property (GObject * object, guint prop_id,
static void gst_rtspsrc_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
static gboolean gst_rtspsrc_uri_set_uri (GstURIHandler * handler,
const gchar * uri);
static void gst_rtspsrc_loop (GstRTSPSrc * src);
/*static guint gst_rtspsrc_signals[LAST_SIGNAL] = { 0 }; */
......@@ -200,7 +203,7 @@ gst_rtspsrc_class_init (GstRTSPSrcClass * klass)
g_object_class_install_property (gobject_class, PROP_LOCATION,
g_param_spec_string ("location", "RTSP Location",
"Location of the RTSP url to read",
DEFAULT_LOCATION, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
DEFAULT_LOCATION, G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, PROP_PROTOCOLS,
g_param_spec_flags ("protocols", "Protocols", "Allowed protocols",
......@@ -226,6 +229,9 @@ gst_rtspsrc_init (GstRTSPSrc * src, GstRTSPSrcClass * g_class)
{
src->stream_rec_lock = g_new (GStaticRecMutex, 1);
g_static_rec_mutex_init (src->stream_rec_lock);
src->location = DEFAULT_LOCATION;
src->url = NULL;
}
static void
......@@ -251,8 +257,8 @@ gst_rtspsrc_set_property (GObject * object, guint prop_id, const GValue * value,
switch (prop_id) {
case PROP_LOCATION:
g_free (rtspsrc->location);
rtspsrc->location = g_value_dup_string (value);
gst_rtspsrc_uri_set_uri (GST_URI_HANDLER (rtspsrc),
g_value_get_string (value));
break;
case PROP_PROTOCOLS:
rtspsrc->protocols = g_value_get_flags (value);
......@@ -947,7 +953,6 @@ error_response:
static gboolean
gst_rtspsrc_open (GstRTSPSrc * src)
{
RTSPUrl *url;
RTSPResult res;
RTSPMessage request = { 0 };
RTSPMessage response = { 0 };
......@@ -956,14 +961,13 @@ gst_rtspsrc_open (GstRTSPSrc * src)
SDPMessage sdp = { 0 };
GstRTSPProto protocols;
/* parse url */
GST_DEBUG_OBJECT (src, "parsing url...");
if ((res = rtsp_url_parse (src->location, &url)) < 0)
goto invalid_url;
/* can't continue without a valid url */
if (src->url == NULL)
goto no_url;
/* open connection */
GST_DEBUG_OBJECT (src, "opening connection...");
if ((res = rtsp_connection_open (url, &src->connection)) < 0)
GST_DEBUG_OBJECT (src, "opening connection (%s)...", src->location);
if ((res = rtsp_connection_open (src->url, &src->connection)) < 0)
goto could_not_open;
/* create OPTIONS */
......@@ -1197,10 +1201,10 @@ gst_rtspsrc_open (GstRTSPSrc * src)
return TRUE;
/* ERRORS */
invalid_url:
no_url:
{
GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
("Not a valid RTSP url."), (NULL));
("No valid RTSP url was provided"), (NULL));
return FALSE;
}
could_not_open:
......@@ -1470,18 +1474,49 @@ gst_rtspsrc_uri_get_uri (GstURIHandler * handler)
{
GstRTSPSrc *src = GST_RTSPSRC (handler);
return g_strdup (src->location);
return src->location;
}
static gboolean
gst_rtspsrc_uri_set_uri (GstURIHandler * handler, const gchar * uri)
{
GstRTSPSrc *src = GST_RTSPSRC (handler);
GstRTSPSrc *src;
RTSPResult res;
RTSPUrl *newurl;
src = GST_RTSPSRC (handler);
/* same URI, we're fine */
if (src->location && uri && !strcmp (uri, src->location))
goto was_ok;
/* try to parse */
if ((res = rtsp_url_parse (uri, &newurl)) < 0)
goto parse_error;
/* if worked, free previous and store new url object along with the original
* location. */
rtsp_url_free (src->url);
src->url = newurl;
g_free (src->location);
src->location = g_strdup (uri);
GST_DEBUG_OBJECT (src, "set uri: %s", GST_STR_NULL (uri));
return TRUE;
/* Special cases */
was_ok:
{
GST_DEBUG_OBJECT (src, "URI was ok: '%s'", GST_STR_NULL (uri));
return TRUE;
}
parse_error:
{
GST_ERROR_OBJECT (src, "Not a valid RTSP url '%s' (%d)", GST_STR_NULL (uri),
res);
return FALSE;
}
}
static void
......
......@@ -96,6 +96,7 @@ struct _GstRTSPSrc {
GList *streams;
gchar *location;
RTSPUrl *url;
gboolean debug;
guint retry;
......
......@@ -196,6 +196,21 @@ rtsp_message_get_body (RTSPMessage * msg, guint8 ** data, guint * size)
return RTSP_OK;
}
RTSPResult
rtsp_message_steal_body (RTSPMessage * msg, guint8 ** data, guint * size)
{
if (msg == NULL || data == NULL || size == NULL)
return RTSP_EINVAL;
*data = msg->body;
*size = msg->body_size;
msg->body = NULL;
msg->body_size = 0;
return RTSP_OK;
}
static void
dump_mem (guint8 * mem, gint size)
{
......
......@@ -77,6 +77,7 @@ RTSPResult rtsp_message_get_header (RTSPMessage *msg, RTSPHeaderFie
RTSPResult rtsp_message_set_body (RTSPMessage *msg, guint8 *data, guint size);
RTSPResult rtsp_message_take_body (RTSPMessage *msg, guint8 *data, guint size);
RTSPResult rtsp_message_get_body (RTSPMessage *msg, guint8 **data, guint *size);
RTSPResult rtsp_message_steal_body (RTSPMessage *msg, guint8 **data, guint *size);
RTSPResult rtsp_message_dump (RTSPMessage *msg);
......
......@@ -94,6 +94,7 @@ rtsp_url_parse (const gchar * urlstr, RTSPUrl ** url)
return RTSP_OK;
/* ERRORS */
invalid:
{
rtsp_url_free (res);
......@@ -104,6 +105,9 @@ invalid:
void
rtsp_url_free (RTSPUrl * url)
{
if (url == NULL)
return;
g_free (url->user);
g_free (url->passwd);
g_free (url->host);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment