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.
This commit is contained in:
Lutz Mueller 2006-09-18 11:29:12 +00:00 committed by Wim Taymans
parent afd156ad0c
commit cac807b641
6 changed files with 87 additions and 14 deletions

View file

@ -1,3 +1,20 @@
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> 2006-09-18 Wim Taymans <wim@fluendo.com>
Based on patch by: Lutz Mueller <lutz at topfrose dot de> Based on patch by: Lutz Mueller <lutz at topfrose dot de>

View file

@ -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, static void gst_rtspsrc_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec); GValue * value, GParamSpec * pspec);
static gboolean gst_rtspsrc_uri_set_uri (GstURIHandler * handler,
const gchar * uri);
static void gst_rtspsrc_loop (GstRTSPSrc * src); static void gst_rtspsrc_loop (GstRTSPSrc * src);
/*static guint gst_rtspsrc_signals[LAST_SIGNAL] = { 0 }; */ /*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_object_class_install_property (gobject_class, PROP_LOCATION,
g_param_spec_string ("location", "RTSP Location", g_param_spec_string ("location", "RTSP Location",
"Location of the RTSP url to read", "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_object_class_install_property (gobject_class, PROP_PROTOCOLS,
g_param_spec_flags ("protocols", "Protocols", "Allowed 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); src->stream_rec_lock = g_new (GStaticRecMutex, 1);
g_static_rec_mutex_init (src->stream_rec_lock); g_static_rec_mutex_init (src->stream_rec_lock);
src->location = DEFAULT_LOCATION;
src->url = NULL;
} }
static void static void
@ -251,8 +257,8 @@ gst_rtspsrc_set_property (GObject * object, guint prop_id, const GValue * value,
switch (prop_id) { switch (prop_id) {
case PROP_LOCATION: case PROP_LOCATION:
g_free (rtspsrc->location); gst_rtspsrc_uri_set_uri (GST_URI_HANDLER (rtspsrc),
rtspsrc->location = g_value_dup_string (value); g_value_get_string (value));
break; break;
case PROP_PROTOCOLS: case PROP_PROTOCOLS:
rtspsrc->protocols = g_value_get_flags (value); rtspsrc->protocols = g_value_get_flags (value);
@ -947,7 +953,6 @@ error_response:
static gboolean static gboolean
gst_rtspsrc_open (GstRTSPSrc * src) gst_rtspsrc_open (GstRTSPSrc * src)
{ {
RTSPUrl *url;
RTSPResult res; RTSPResult res;
RTSPMessage request = { 0 }; RTSPMessage request = { 0 };
RTSPMessage response = { 0 }; RTSPMessage response = { 0 };
@ -956,14 +961,13 @@ gst_rtspsrc_open (GstRTSPSrc * src)
SDPMessage sdp = { 0 }; SDPMessage sdp = { 0 };
GstRTSPProto protocols; GstRTSPProto protocols;
/* parse url */ /* can't continue without a valid url */
GST_DEBUG_OBJECT (src, "parsing url..."); if (src->url == NULL)
if ((res = rtsp_url_parse (src->location, &url)) < 0) goto no_url;
goto invalid_url;
/* open connection */ /* open connection */
GST_DEBUG_OBJECT (src, "opening connection..."); GST_DEBUG_OBJECT (src, "opening connection (%s)...", src->location);
if ((res = rtsp_connection_open (url, &src->connection)) < 0) if ((res = rtsp_connection_open (src->url, &src->connection)) < 0)
goto could_not_open; goto could_not_open;
/* create OPTIONS */ /* create OPTIONS */
@ -1197,10 +1201,10 @@ gst_rtspsrc_open (GstRTSPSrc * src)
return TRUE; return TRUE;
/* ERRORS */ /* ERRORS */
invalid_url: no_url:
{ {
GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND,
("Not a valid RTSP url."), (NULL)); ("No valid RTSP url was provided"), (NULL));
return FALSE; return FALSE;
} }
could_not_open: could_not_open:
@ -1470,18 +1474,49 @@ gst_rtspsrc_uri_get_uri (GstURIHandler * handler)
{ {
GstRTSPSrc *src = GST_RTSPSRC (handler); GstRTSPSrc *src = GST_RTSPSRC (handler);
return g_strdup (src->location); return src->location;
} }
static gboolean static gboolean
gst_rtspsrc_uri_set_uri (GstURIHandler * handler, const gchar * uri) 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); g_free (src->location);
src->location = g_strdup (uri); src->location = g_strdup (uri);
GST_DEBUG_OBJECT (src, "set uri: %s", GST_STR_NULL (uri));
return TRUE; 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 static void

View file

@ -96,6 +96,7 @@ struct _GstRTSPSrc {
GList *streams; GList *streams;
gchar *location; gchar *location;
RTSPUrl *url;
gboolean debug; gboolean debug;
guint retry; guint retry;

View file

@ -196,6 +196,21 @@ rtsp_message_get_body (RTSPMessage * msg, guint8 ** data, guint * size)
return RTSP_OK; 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 static void
dump_mem (guint8 * mem, gint size) dump_mem (guint8 * mem, gint size)
{ {

View file

@ -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_set_body (RTSPMessage *msg, guint8 *data, guint size);
RTSPResult rtsp_message_take_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_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); RTSPResult rtsp_message_dump (RTSPMessage *msg);

View file

@ -94,6 +94,7 @@ rtsp_url_parse (const gchar * urlstr, RTSPUrl ** url)
return RTSP_OK; return RTSP_OK;
/* ERRORS */
invalid: invalid:
{ {
rtsp_url_free (res); rtsp_url_free (res);
@ -104,6 +105,9 @@ invalid:
void void
rtsp_url_free (RTSPUrl * url) rtsp_url_free (RTSPUrl * url)
{ {
if (url == NULL)
return;
g_free (url->user); g_free (url->user);
g_free (url->passwd); g_free (url->passwd);
g_free (url->host); g_free (url->host);