[gnio/connection-factory: 8/8] Use the GNetworkAddress parsing function
- From: Alexander Larsson <alexl src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnio/connection-factory: 8/8] Use the GNetworkAddress parsing function
- Date: Thu, 14 May 2009 13:21:13 -0400 (EDT)
commit 55a68c1a0b3dfb98bac951a98ed3087c7fe6fe5b
Author: Alexander Larsson <alexl redhat com>
Date: Thu May 14 19:13:46 2009 +0200
Use the GNetworkAddress parsing function
g_network_address_new_from_string moved to glib as g_network_address_parse.
---
gio/gsocketclient.c | 144 +-------------------------------------------------
1 files changed, 3 insertions(+), 141 deletions(-)
diff --git a/gio/gsocketclient.c b/gio/gsocketclient.c
index 40bf524..b121b4c 100644
--- a/gio/gsocketclient.c
+++ b/gio/gsocketclient.c
@@ -284,144 +284,6 @@ g_socket_client_connect (GSocketClient *client,
return connection;
}
-static GSocketConnectable *
-g_network_address_new_from_string (const char *host_and_port,
- int default_port,
- GError **error)
-{
- GSocketConnectable *connectable;
- const gchar *port;
- guint16 portnum;
- gchar *name;
-
- g_return_val_if_fail (host_and_port != NULL, NULL);
-
- port = NULL;
- if (host_and_port[0] == '[')
- /* escaped host part (to allow, eg. "[2001:db8::1]:888") */
- {
- const gchar *end;
-
- end = strchr (host_and_port, ']');
-
- if (end == NULL)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- _("Hostname '%s' contains '[' but not ']'"), host_and_port);
- return NULL;
- }
-
- if (end[1] == '\0')
- port = NULL;
- else if (end[1] == ':')
- port = &end[2];
- else
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "The ']' character (in hostname '%s') must come at the"
- " end or be immediately followed by ':' and a port",
- host_and_port);
- return NULL;
- }
-
- name = g_strndup (host_and_port + 1, end - host_and_port - 1);
- }
-
- else if ((port = strchr (host_and_port, ':')))
- /* string has a ':' in it */
- {
- /* skip ':' */
- port++;
-
- if (strchr (port, ':'))
- /* more than one ':' in string */
- {
- /* this is actually an unescaped IPv6 address */
- name = g_strdup (host_and_port);
- port = NULL;
- }
- else
- name = g_strndup (host_and_port, port - host_and_port - 1);
- }
-
- else
- /* plain hostname, no port */
- name = g_strdup (host_and_port);
-
- if (port != NULL)
- {
- if (port[0] == '\0')
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "If a ':' character is given, it must be followed by a "
- "port (in hostname '%s').", host_and_port);
- g_free (name);
- return NULL;
- }
-
- else if ('0' <= port[0] && port[0] <= '9')
- {
- char *end;
- long value;
-
- value = strtol (port, &end, 10);
- if (*end != '\0' || value <= 0 || value > G_MAXUINT16)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Invalid numeric port '%s' specified in hostname '%s'",
- port, host_and_port);
- g_free (name);
- return NULL;
- }
-
- portnum = value;
- }
-
- else
- {
- struct servent *entry;
-
- entry = getservbyname (port, "tcp");
- if (entry == NULL)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Unknown service '%s' specified in hostname '%s'",
- port, host_and_port);
-#ifdef HAVE_ENDSERVENT
- endservent ();
-#endif
- g_free (name);
- return NULL;
- }
-
- portnum = g_ntohs (entry->s_port);
-
-#ifdef HAVE_ENDSERVENT
- endservent ();
-#endif
- }
- }
- else
- {
- /* No port in host_and_port */
-
- if (default_port <= 0 || default_port > G_MAXUINT16)
- {
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "Invalid numeric default port '%d' specified",
- default_port);
- g_free (name);
- return NULL;
- }
- portnum = default_port;
- }
-
- connectable = g_network_address_new (name, portnum);
- g_free (name);
-
- return connectable;
-}
-
/**
* g_socket_client_connect_to_host:
* @client: a #GTcpClient
@@ -472,7 +334,7 @@ g_socket_client_connect_to_host (GSocketClient *client,
GSocketConnectable *connectable;
GSocketConnection *connection;
- connectable = g_network_address_new_from_string (host_and_port, default_port, error);
+ connectable = g_network_address_parse (host_and_port, default_port, error);
if (connectable == NULL)
return NULL;
@@ -704,8 +566,8 @@ g_socket_client_connect_to_host_async (GSocketClient *client,
GError *error;
error = NULL;
- connectable = g_network_address_new_from_string (host_and_port, default_port,
- &error);
+ connectable = g_network_address_parse (host_and_port, default_port,
+ &error);
if (connectable == NULL)
{
g_simple_async_report_gerror_in_idle (G_OBJECT (client),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]