/* GStreamer UDP network utility functions
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
* Copyright (C) 2006 Joni Valtanen <joni.valtanen@movial.fi>
+ * Copyright (C) 2009 Jarkko Palviainen <jarkko.palviainen@sesca.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#include "gstudpnetutils.h"
+#include <gst/gst.h>
+#include <string.h>
-#ifdef G_OS_WIN32
+#include "gstudpnetutils.h"
-int
-gst_udp_net_utils_win32_inet_aton (const char *c, struct in_addr *paddr)
+gboolean
+gst_udp_parse_uri (const gchar * uristr, gchar ** host, guint16 * port)
{
- paddr->s_addr = inet_addr (c);
+ gchar *protocol, *location_start;
+ gchar *location, *location_end;
+ gchar *colptr;
- if (paddr->s_addr == INADDR_NONE)
- return 0;
+ /* consider no protocol to be udp:// */
+ protocol = gst_uri_get_protocol (uristr);
+ if (!protocol)
+ goto no_protocol;
+ if (strcmp (protocol, "udp") != 0)
+ goto wrong_protocol;
+ g_free (protocol);
- return 1;
-}
+ location_start = gst_uri_get_location (uristr);
+ if (!location_start)
+ return FALSE;
-gboolean
-gst_udp_net_utils_win32_wsa_startup (GstObject * obj)
-{
- WSADATA w;
- int error;
+ GST_DEBUG ("got location '%s'", location_start);
- error = WSAStartup (0x0202, &w);
+ /* 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;
- if (error) {
- GST_WARNING_OBJECT (obj, "WSAStartup error: %d", error);
- return FALSE;
+ if (location[0] == '[') {
+ GST_DEBUG ("parse IPV6 address '%s'", location);
+ location_end = strchr (location, ']');
+ if (location_end == NULL)
+ goto wrong_address;
+
+ *host = g_strndup (location + 1, location_end - location - 1);
+ colptr = strrchr (location_end, ':');
+ } else {
+ GST_DEBUG ("parse IPV4 address '%s'", location);
+ colptr = strrchr (location, ':');
+
+ if (colptr != NULL) {
+ *host = g_strndup (location, colptr - location);
+ } else {
+ *host = g_strdup (location);
+ }
}
+ GST_DEBUG ("host set to '%s'", *host);
- if (w.wVersion != 0x0202) {
- WSACleanup ();
- GST_WARNING_OBJECT (obj, "Winsock version wrong : 0x%x", w.wVersion);
- return FALSE;
+ if (colptr != NULL) {
+ *port = g_ascii_strtoll (colptr + 1, NULL, 10);
+ } else {
+ *port = 0;
}
+ g_free (location_start);
return TRUE;
-}
-#endif
+ /* ERRORS */
+no_protocol:
+ {
+ GST_ERROR ("error parsing uri %s: no protocol", uristr);
+ return FALSE;
+ }
+wrong_protocol:
+ {
+ GST_ERROR ("error parsing uri %s: wrong protocol (%s != udp)", uristr,
+ protocol);
+ g_free (protocol);
+ return FALSE;
+ }
+wrong_address:
+ {
+ GST_ERROR ("error parsing uri %s", uristr);
+ g_free (location);
+ return FALSE;
+ }
+}