2006-07-24 11:48:03 +00:00
|
|
|
/* GStreamer UDP network utility functions
|
|
|
|
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
|
|
|
|
* Copyright (C) 2006 Joni Valtanen <joni.valtanen@movial.fi>
|
2009-08-31 10:16:01 +00:00
|
|
|
* Copyright (C) 2009 Jarkko Palviainen <jarkko.palviainen@sesca.com>
|
2006-07-24 11:48:03 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-04 00:07:18 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2006-07-24 11:48:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2010-03-09 16:13:31 +00:00
|
|
|
#include <gst/gst.h>
|
2012-01-17 10:18:33 +00:00
|
|
|
#include <string.h>
|
2010-03-09 16:13:31 +00:00
|
|
|
|
2009-06-23 13:10:10 +00:00
|
|
|
#include "gstudpnetutils.h"
|
|
|
|
|
2012-01-17 08:03:38 +00:00
|
|
|
gboolean
|
|
|
|
gst_udp_parse_uri (const gchar * uristr, gchar ** host, guint16 * port)
|
2010-03-09 16:13:31 +00:00
|
|
|
{
|
2010-06-18 14:16:28 +00:00
|
|
|
gchar *protocol, *location_start;
|
2010-03-09 16:13:31 +00:00
|
|
|
gchar *location, *location_end;
|
|
|
|
gchar *colptr;
|
|
|
|
|
2011-09-05 09:11:18 +00:00
|
|
|
/* consider no protocol to be udp:// */
|
2010-03-09 16:13:31 +00:00
|
|
|
protocol = gst_uri_get_protocol (uristr);
|
2011-09-05 09:11:18 +00:00
|
|
|
if (!protocol)
|
|
|
|
goto no_protocol;
|
2010-03-09 16:13:31 +00:00
|
|
|
if (strcmp (protocol, "udp") != 0)
|
|
|
|
goto wrong_protocol;
|
|
|
|
g_free (protocol);
|
|
|
|
|
2010-06-18 14:16:28 +00:00
|
|
|
location_start = gst_uri_get_location (uristr);
|
|
|
|
if (!location_start)
|
2010-03-09 16:13:31 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-06-18 14:16:28 +00:00
|
|
|
GST_DEBUG ("got location '%s'", location_start);
|
|
|
|
|
|
|
|
/* VLC compatibility, strip everything before the @ sign. VLC uses that as the
|
|
|
|
* remote address. */
|
|
|
|
location = g_strstr_len (location_start, -1, "@");
|
|
|
|
if (location == NULL)
|
|
|
|
location = location_start;
|
|
|
|
else
|
|
|
|
location += 1;
|
2010-03-09 16:13:31 +00:00
|
|
|
|
|
|
|
if (location[0] == '[') {
|
|
|
|
GST_DEBUG ("parse IPV6 address '%s'", location);
|
|
|
|
location_end = strchr (location, ']');
|
|
|
|
if (location_end == NULL)
|
|
|
|
goto wrong_address;
|
|
|
|
|
2012-01-17 08:03:38 +00:00
|
|
|
*host = g_strndup (location + 1, location_end - location - 1);
|
2010-03-09 16:13:31 +00:00
|
|
|
colptr = strrchr (location_end, ':');
|
|
|
|
} else {
|
|
|
|
GST_DEBUG ("parse IPV4 address '%s'", location);
|
|
|
|
colptr = strrchr (location, ':');
|
|
|
|
|
|
|
|
if (colptr != NULL) {
|
2012-01-17 08:03:38 +00:00
|
|
|
*host = g_strndup (location, colptr - location);
|
2010-03-09 16:13:31 +00:00
|
|
|
} else {
|
2012-01-17 08:03:38 +00:00
|
|
|
*host = g_strdup (location);
|
2010-03-09 16:13:31 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-17 08:03:38 +00:00
|
|
|
GST_DEBUG ("host set to '%s'", *host);
|
2010-03-09 16:13:31 +00:00
|
|
|
|
|
|
|
if (colptr != NULL) {
|
2012-01-17 10:18:33 +00:00
|
|
|
*port = g_ascii_strtoll (colptr + 1, NULL, 10);
|
|
|
|
} else {
|
|
|
|
*port = 0;
|
2010-03-09 16:13:31 +00:00
|
|
|
}
|
2010-06-18 14:16:28 +00:00
|
|
|
g_free (location_start);
|
2010-03-09 16:13:31 +00:00
|
|
|
|
2012-01-17 08:03:38 +00:00
|
|
|
return TRUE;
|
2010-03-09 16:13:31 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
2011-09-05 09:11:18 +00:00
|
|
|
no_protocol:
|
|
|
|
{
|
|
|
|
GST_ERROR ("error parsing uri %s: no protocol", uristr);
|
2012-01-17 08:03:38 +00:00
|
|
|
return FALSE;
|
2011-09-05 09:11:18 +00:00
|
|
|
}
|
2010-03-09 16:13:31 +00:00
|
|
|
wrong_protocol:
|
|
|
|
{
|
|
|
|
GST_ERROR ("error parsing uri %s: wrong protocol (%s != udp)", uristr,
|
|
|
|
protocol);
|
|
|
|
g_free (protocol);
|
2012-01-17 08:03:38 +00:00
|
|
|
return FALSE;
|
2010-03-09 16:13:31 +00:00
|
|
|
}
|
|
|
|
wrong_address:
|
|
|
|
{
|
|
|
|
GST_ERROR ("error parsing uri %s", uristr);
|
|
|
|
g_free (location);
|
2012-01-17 08:03:38 +00:00
|
|
|
return FALSE;
|
2010-03-09 16:13:31 +00:00
|
|
|
}
|
|
|
|
}
|